Skip to content

Commit

Permalink
Merge pull request onevcat#1574 from onevcat/combine-pods
Browse files Browse the repository at this point in the history
Merge SwiftUI support to the core library
  • Loading branch information
onevcat authored Dec 16, 2020
2 parents f4a5c8e + d3ff773 commit a8c662b
Show file tree
Hide file tree
Showing 17 changed files with 94 additions and 769 deletions.
38 changes: 36 additions & 2 deletions Demo/Demo/Kingfisher-Demo/Base.lproj/Main.storyboard
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="17156" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES" initialViewController="peg-r0-mlo">
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="17701" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES" initialViewController="peg-r0-mlo">
<device id="retina5_5" orientation="portrait" appearance="dark"/>
<dependencies>
<deployment identifier="iOS"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="17125"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="17703"/>
<capability name="Safe area layout guides" minToolsVersion="9.0"/>
<capability name="System colors in document resources" minToolsVersion="11.0"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
Expand Down Expand Up @@ -395,6 +395,30 @@
<segue destination="m5P-35-yHH" kind="show" id="iY4-PO-rZO"/>
</connections>
</tableViewCell>
<tableViewCell clipsSubviews="YES" contentMode="scaleToFill" preservesSuperviewLayoutMargins="YES" selectionStyle="default" indentationWidth="10" id="TIF-8x-GLM">
<rect key="frame" x="0.0" y="512" width="414" height="44"/>
<autoresizingMask key="autoresizingMask"/>
<tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" preservesSuperviewLayoutMargins="YES" insetsLayoutMarginsFromSafeArea="NO" tableViewCell="TIF-8x-GLM" id="ykx-Ds-PkP">
<rect key="frame" x="0.0" y="0.0" width="414" height="44"/>
<autoresizingMask key="autoresizingMask"/>
<subviews>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="SwiftUI" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="8BM-EA-MyK">
<rect key="frame" x="19.999999999999996" y="11.666666666666664" width="54.666666666666657" height="21"/>
<fontDescription key="fontDescription" type="system" pointSize="17"/>
<nil key="textColor"/>
<nil key="highlightedColor"/>
</label>
</subviews>
<constraints>
<constraint firstAttribute="trailing" relation="greaterThanOrEqual" secondItem="8BM-EA-MyK" secondAttribute="trailing" constant="20" symbolic="YES" id="HIp-se-68O"/>
<constraint firstItem="8BM-EA-MyK" firstAttribute="centerY" secondItem="ykx-Ds-PkP" secondAttribute="centerY" id="YjV-XQ-ZBh"/>
<constraint firstItem="8BM-EA-MyK" firstAttribute="leading" secondItem="ykx-Ds-PkP" secondAttribute="leading" constant="20" symbolic="YES" id="wxa-xN-XPx"/>
</constraints>
</tableViewCellContentView>
<connections>
<segue destination="7fx-Ak-QCf" kind="show" id="1FN-t9-66q"/>
</connections>
</tableViewCell>
</cells>
</tableViewSection>
</sections>
Expand Down Expand Up @@ -888,6 +912,16 @@
</objects>
<point key="canvasLocation" x="1850.7246376811595" y="1735.5978260869567"/>
</scene>
<!--SwiftUI View Controller-->
<scene sceneID="rw7-vi-6Ep">
<objects>
<hostingController id="7fx-Ak-QCf" customClass="SwiftUIViewController" customModule="Kingfisher_Demo" customModuleProvider="target" sceneMemberID="viewController">
<navigationItem key="navigationItem" id="TII-JX-FOz"/>
</hostingController>
<placeholder placeholderIdentifier="IBFirstResponder" id="ep4-jy-p4V" userLabel="First Responder" customClass="UIResponder" sceneMemberID="firstResponder"/>
</objects>
<point key="canvasLocation" x="1043" y="1452"/>
</scene>
</scenes>
<resources>
<systemColor name="secondaryLabelColor">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,33 +25,30 @@
// THE SOFTWARE.

import SwiftUI
import class Kingfisher.KingfisherManager
import Kingfisher

@available(iOS 13.0, *)
struct MainView: View {
var body: some View {

NavigationView {
List {
Button(
action: {
KingfisherManager.shared.cache.clearMemoryCache()
KingfisherManager.shared.cache.clearDiskCache()
},
label: {
Text("Clear Cache").foregroundColor(.blue)
}
)
NavigationLink(destination: SwiftUIView()) { Text("Basic Image") }
NavigationLink(destination: SwiftUIList()) { Text("List") }
}.navigationBarTitle(Text("Kingfisher"))
}
List {
Button(
action: {
KingfisherManager.shared.cache.clearMemoryCache()
KingfisherManager.shared.cache.clearDiskCache()
},
label: {
Text("Clear Cache").foregroundColor(.blue)
}
)
NavigationLink(destination: SwiftUIView()) { Text("Basic Image") }
NavigationLink(destination: SwiftUIList()) { Text("List") }
}.navigationBarTitle(Text("SwiftUI Sample"))
}
}

#if DEBUG
@available(iOS 13.0, *)
struct MainView_Previews: PreviewProvider {
static var previews: some View {
MainView()
}
}
#endif
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.

import class Kingfisher.ImageCache
import KingfisherSwiftUI
import Kingfisher
import SwiftUI

@available(iOS 13.0, *)
struct SwiftUIList : View {

let index = 1 ..< 700
Expand Down Expand Up @@ -89,10 +89,9 @@ struct SwiftUIList : View {
}
}

#if DEBUG
@available(iOS 13.0, *)
struct SwiftUIList_Previews : PreviewProvider {
static var previews: some View {
SwiftUIList()
}
}
#endif
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,10 @@
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.

import KingfisherSwiftUI
import Kingfisher
import SwiftUI

@available(iOS 13.0, *)
struct SwiftUIView : View {

@State private var index = 1
Expand Down Expand Up @@ -58,10 +59,9 @@ struct SwiftUIView : View {
}
}

#if DEBUG
@available(iOS 13.0, *)
struct SwiftUIView_Previews : PreviewProvider {
static var previews: some View {
SwiftUIView()
}
}
#endif
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
//
// Delegate.swift
// SwiftUIViewController.swift
// Kingfisher
//
// Created by onevcat on 2018/10/10.
// Created by onevcat on 2020/12/16.
//
// Copyright (c) 2019 Wei Wang <[email protected]>
// Copyright (c) 2020 Wei Wang <[email protected]>
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
Expand All @@ -24,30 +24,16 @@
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.

import Foundation
import SwiftUI
import UIKit

/// A delegate helper type to "shadow" weak `self`, to prevent creating an unexpected retain cycle.
class Delegate<Input, Output> {
init() {}

private var block: ((Input) -> Output?)?

func delegate<T: AnyObject>(on target: T, block: ((T, Input) -> Output)?) {
// The `target` is weak inside block, so you do not need to worry about it in the caller side.
self.block = { [weak target] input in
guard let target = target else { return nil }
return block?(target, input)
}
@available(iOS 13.0, *)
class SwiftUIViewController: UIHostingController<MainView> {
required init?(coder: NSCoder) {
super.init(coder: coder,rootView: MainView());
}

func call(_ input: Input) -> Output? {
return block?(input)
}
}

extension Delegate where Input == Void {
// To make syntax better for `Void` input.
func call() -> Output? {
return call(())
override func viewDidLoad() {
super.viewDidLoad()
}
}
55 changes: 0 additions & 55 deletions Demo/Demo/Kingfisher-SwiftUI-Demo/AppDelegate.swift

This file was deleted.

This file was deleted.

This file was deleted.

Loading

0 comments on commit a8c662b

Please sign in to comment.