Skip to content

Commit

Permalink
Improve the SwiftUI support a bit
Browse files Browse the repository at this point in the history
  • Loading branch information
JanGorman committed Jan 3, 2022
1 parent 090b9c2 commit 7242ab8
Show file tree
Hide file tree
Showing 6 changed files with 191 additions and 55 deletions.
4 changes: 4 additions & 0 deletions Agrume.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
/* Begin PBXBuildFile section */
833C23CA23CC800800F689E2 /* AgrumePhotoLibraryHelper.swift in Sources */ = {isa = PBXBuildFile; fileRef = 833C23C923CC800800F689E2 /* AgrumePhotoLibraryHelper.swift */; };
94318E541D32612D0096215A /* AgrumeServiceLocator.swift in Sources */ = {isa = PBXBuildFile; fileRef = 94318E531D32612D0096215A /* AgrumeServiceLocator.swift */; };
F224A7392783301200A8F5ED /* AgrumeView.swift in Sources */ = {isa = PBXBuildFile; fileRef = F224A7362783301200A8F5ED /* AgrumeView.swift */; };
F2539BA120F22E7700062C80 /* AgrumeOverlayView.swift in Sources */ = {isa = PBXBuildFile; fileRef = F2539BA020F22E7700062C80 /* AgrumeOverlayView.swift */; };
F2609E23209F047200E0E93D /* AgrumeDataSource.swift in Sources */ = {isa = PBXBuildFile; fileRef = F2609E22209F047200E0E93D /* AgrumeDataSource.swift */; };
F2609E26209F06F800E0E93D /* AgrumeImage.swift in Sources */ = {isa = PBXBuildFile; fileRef = F2609E25209F06F800E0E93D /* AgrumeImage.swift */; };
Expand Down Expand Up @@ -51,6 +52,7 @@
/* Begin PBXFileReference section */
833C23C923CC800800F689E2 /* AgrumePhotoLibraryHelper.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AgrumePhotoLibraryHelper.swift; sourceTree = "<group>"; };
94318E531D32612D0096215A /* AgrumeServiceLocator.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AgrumeServiceLocator.swift; sourceTree = "<group>"; };
F224A7362783301200A8F5ED /* AgrumeView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AgrumeView.swift; sourceTree = "<group>"; };
F2539BA020F22E7700062C80 /* AgrumeOverlayView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AgrumeOverlayView.swift; sourceTree = "<group>"; };
F2609E22209F047200E0E93D /* AgrumeDataSource.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AgrumeDataSource.swift; sourceTree = "<group>"; };
F2609E25209F06F800E0E93D /* AgrumeImage.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AgrumeImage.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -128,6 +130,7 @@
F2609E25209F06F800E0E93D /* AgrumeImage.swift */,
F2539BA020F22E7700062C80 /* AgrumeOverlayView.swift */,
94318E531D32612D0096215A /* AgrumeServiceLocator.swift */,
F224A7362783301200A8F5ED /* AgrumeView.swift */,
F2609E27209F2BC600E0E93D /* Configuration.swift */,
F2EE29AD209F31B800F281A2 /* Foundation+Agrume.swift */,
833C23C923CC800800F689E2 /* AgrumePhotoLibraryHelper.swift */,
Expand Down Expand Up @@ -335,6 +338,7 @@
F2DC79D61B170C4B00818A8C /* ImageDownloader.swift in Sources */,
F2539BA120F22E7700062C80 /* AgrumeOverlayView.swift in Sources */,
F2609E23209F047200E0E93D /* AgrumeDataSource.swift in Sources */,
F224A7392783301200A8F5ED /* AgrumeView.swift in Sources */,
F2A5200B1B10E29B00924912 /* Agrume.swift in Sources */,
94318E541D32612D0096215A /* AgrumeServiceLocator.swift in Sources */,
);
Expand Down
49 changes: 39 additions & 10 deletions Agrume/AgrumeView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4,25 +4,54 @@

import SwiftUI

public struct AgrumeView: UIViewControllerRepresentable {
let image: UIImage
@available(iOS 14.0, *)
public struct AgrumeView: View {

public init(image: UIImage) {
self.image = image
private let images: [UIImage]
@Binding private var binding: Bool
@Namespace var namespace

public init(image: UIImage, isPresenting: Binding<Bool>) {
self.init(images: [image], isPresenting: isPresenting)
}

public init(images: [UIImage], isPresenting: Binding<Bool>) {
self.images = images
self._binding = isPresenting
}

public var body: some View {
WrapperAgrumeView(images: images, isPresenting: $binding)
.matchedGeometryEffect(id: "AgrumeView", in: namespace, properties: .frame, isSource: binding)
.ignoresSafeArea()
}
}

@available(iOS 13.0, *)
struct WrapperAgrumeView: UIViewControllerRepresentable {

private let images: [UIImage]
@Binding private var binding: Bool

public init(images: [UIImage], isPresenting: Binding<Bool>) {
self.images = images
self._binding = isPresenting
}

public func makeUIViewController(context: UIViewControllerRepresentableContext<AgrumeView>) -> Agrume {
let agrume = Agrume(image: self.image)
public func makeUIViewController(context: UIViewControllerRepresentableContext<WrapperAgrumeView>) -> UIViewController {
let agrume = Agrume(images: images)
agrume.view.backgroundColor = .clear
agrume.addSubviews()
agrume.addOverlayView()
agrume.willDismiss = {
agrume.view.superview?.backgroundColor = .clear
agrume.view.superview?.superview?.backgroundColor = .clear
withAnimation {
binding = false
}
}
return agrume
}

public func updateUIViewController(_ uiViewController: Agrume,
context: UIViewControllerRepresentableContext<AgrumeView>) {
public func updateUIViewController(_ uiViewController: UIViewController,
context: UIViewControllerRepresentableContext<WrapperAgrumeView>) {
}
}
8 changes: 6 additions & 2 deletions Example/Agrume Example.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
94D6B2121E1411B100927735 /* SingeImageBackgroundColorViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 94D6B2111E1411B100927735 /* SingeImageBackgroundColorViewController.swift */; };
E77809E31D17821400CC60F1 /* SingleImageModalViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = E77809E21D17821400CC60F1 /* SingleImageModalViewController.swift */; };
F20F5BD41B134CAF00F9F499 /* Agrume.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = F2A520401B130CC000924912 /* Agrume.framework */; };
F224A73227832DD900A8F5ED /* SwiftUIExampleViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = F224A73127832DD900A8F5ED /* SwiftUIExampleViewController.swift */; };
F2539BCB20F23ABB00062C80 /* CloseButtonViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = F2539BCA20F23ABB00062C80 /* CloseButtonViewController.swift */; };
F2539BD020F23F2F00062C80 /* Agrume.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = F2A520401B130CC000924912 /* Agrume.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; };
F2539BD420F2418900062C80 /* CustomCloseButtonViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = F2539BD320F2418900062C80 /* CustomCloseButtonViewController.swift */; };
Expand Down Expand Up @@ -92,6 +93,7 @@
948117D623C7A83600AE200D /* MultipleImagesCustomOverlayView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MultipleImagesCustomOverlayView.swift; sourceTree = "<group>"; };
94D6B2111E1411B100927735 /* SingeImageBackgroundColorViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SingeImageBackgroundColorViewController.swift; sourceTree = "<group>"; };
E77809E21D17821400CC60F1 /* SingleImageModalViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SingleImageModalViewController.swift; sourceTree = "<group>"; };
F224A73127832DD900A8F5ED /* SwiftUIExampleViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SwiftUIExampleViewController.swift; sourceTree = "<group>"; };
F2539B9D20F22D9000062C80 /* SwiftyGif.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; path = SwiftyGif.framework; sourceTree = BUILT_PRODUCTS_DIR; };
F2539BCA20F23ABB00062C80 /* CloseButtonViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CloseButtonViewController.swift; sourceTree = "<group>"; };
F2539BD320F2418900062C80 /* CustomCloseButtonViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CustomCloseButtonViewController.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -178,6 +180,7 @@
F2A520211B130C7E00924912 /* Images.xcassets */,
F2A520231B130C7E00924912 /* LaunchScreen.xib */,
F2A5201E1B130C7E00924912 /* Main.storyboard */,
F224A73127832DD900A8F5ED /* SwiftUIExampleViewController.swift */,
F2D959921B1A153F00073772 /* MultipleImagesCollectionViewController.swift */,
F2D959961B1A199F00073772 /* MultipleURLsCollectionViewController.swift */,
948117D623C7A83600AE200D /* MultipleImagesCustomOverlayView.swift */,
Expand Down Expand Up @@ -369,6 +372,7 @@
F2A5201B1B130C7E00924912 /* AppDelegate.swift in Sources */,
9464AFE923C692C7006ADEBD /* OverlayView.swift in Sources */,
F2D959971B1A199F00073772 /* MultipleURLsCollectionViewController.swift in Sources */,
F224A73227832DD900A8F5ED /* SwiftUIExampleViewController.swift in Sources */,
F2D959931B1A153F00073772 /* MultipleImagesCollectionViewController.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
Expand Down Expand Up @@ -469,7 +473,7 @@
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 12.0;
IPHONEOS_DEPLOYMENT_TARGET = 14.0;
MTL_ENABLE_DEBUG_INFO = YES;
ONLY_ACTIVE_ARCH = YES;
SDKROOT = iphoneos;
Expand Down Expand Up @@ -519,7 +523,7 @@
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 12.0;
IPHONEOS_DEPLOYMENT_TARGET = 14.0;
MTL_ENABLE_DEBUG_INFO = NO;
SDKROOT = iphoneos;
SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule";
Expand Down
Loading

0 comments on commit 7242ab8

Please sign in to comment.