Skip to content

Commit

Permalink
Redo of Enables application extension API only #557 (#681)
Browse files Browse the repository at this point in the history
* Enables application extension API only

* Replace UIApp...leftToRight with Locale extension

For use in Extensions that don't support UIApp

Co-authored-by: Lukas Schmidt <lukas.la.schmidt@deutschebahn.com>
  • Loading branch information
JoeMatt and lightsprint09 committed Feb 8, 2021
1 parent 2de8d78 commit 800b9d9
Show file tree
Hide file tree
Showing 7 changed files with 51 additions and 5 deletions.
2 changes: 1 addition & 1 deletion Examples/SwiftUIMatchExample.swift
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ struct ImageInfo: Identifiable {
struct ImagesTableView: View {
var dismiss: (() -> Void)?
var onTapRow: ((ImageInfo)->())?

@State var images = (0...9).map{ ImageInfo(id: $0, name: "Unsplash\($0)") }

var body: some View {
Expand Down
10 changes: 10 additions & 0 deletions Hero.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,8 @@
B1D816EC1EF5A720007B9776 /* HeroTransition+Animate.swift in Sources */ = {isa = PBXBuildFile; fileRef = B1D816EA1EF5A720007B9776 /* HeroTransition+Animate.swift */; };
B1D834041F02E7C0009E1E36 /* ConditionalPreprocessor.swift in Sources */ = {isa = PBXBuildFile; fileRef = B1D834031F02E7C0009E1E36 /* ConditionalPreprocessor.swift */; };
B1D834051F02E7C0009E1E36 /* ConditionalPreprocessor.swift in Sources */ = {isa = PBXBuildFile; fileRef = B1D834031F02E7C0009E1E36 /* ConditionalPreprocessor.swift */; };
B35264CE2454FEF300D33861 /* Locale+Hero.swift in Sources */ = {isa = PBXBuildFile; fileRef = B35264CD2454FEF300D33861 /* Locale+Hero.swift */; };
B35264CF2454FEF300D33861 /* Locale+Hero.swift in Sources */ = {isa = PBXBuildFile; fileRef = B35264CD2454FEF300D33861 /* Locale+Hero.swift */; };
DBA05BB41A704A4A17967918 /* Pods_HeroTests.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 841FFA357ACB279D3F74CDEE /* Pods_HeroTests.framework */; };
F482F0BE235D7808002E97ED /* UIColor+HexString.swift in Sources */ = {isa = PBXBuildFile; fileRef = F482F0BD235D7808002E97ED /* UIColor+HexString.swift */; };
F482F0BF235D7808002E97ED /* UIColor+HexString.swift in Sources */ = {isa = PBXBuildFile; fileRef = F482F0BD235D7808002E97ED /* UIColor+HexString.swift */; };
Expand Down Expand Up @@ -285,6 +287,7 @@
B1D816E71EF5A6FE007B9776 /* HeroTransition+Complete.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "HeroTransition+Complete.swift"; sourceTree = "<group>"; };
B1D816EA1EF5A720007B9776 /* HeroTransition+Animate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "HeroTransition+Animate.swift"; sourceTree = "<group>"; };
B1D834031F02E7C0009E1E36 /* ConditionalPreprocessor.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ConditionalPreprocessor.swift; sourceTree = "<group>"; };
B35264CD2454FEF300D33861 /* Locale+Hero.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Locale+Hero.swift"; sourceTree = "<group>"; };
C377744CBFF1E24426E80F55 /* Pods-HeroExamples.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-HeroExamples.release.xcconfig"; path = "Pods/Target Support Files/Pods-HeroExamples/Pods-HeroExamples.release.xcconfig"; sourceTree = "<group>"; };
C51A6465EC2CB38D82F28B93 /* Pods-HeroTests.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-HeroTests.debug.xcconfig"; path = "Pods/Target Support Files/Pods-HeroTests/Pods-HeroTests.debug.xcconfig"; sourceTree = "<group>"; };
EEE340F89FF0A49DD23A5A6E /* Pods_HeroExamples.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_HeroExamples.framework; sourceTree = BUILT_PRODUCTS_DIR; };
Expand Down Expand Up @@ -355,6 +358,7 @@
A37D7B471E2C0C9300AC1959 /* CAMediaTimingFunction+Hero.swift */,
A37D7B481E2C0C9300AC1959 /* CG+Hero.swift */,
A37D7B491E2C0C9300AC1959 /* DispatchQueue+Hero.swift */,
B35264CD2454FEF300D33861 /* Locale+Hero.swift */,
A37D7B4A1E2C0C9300AC1959 /* UIKit+Hero.swift */,
B101B2C91E561408007E7112 /* UIView+Hero.swift */,
B101B2CD1E561421007E7112 /* UIViewController+Hero.swift */,
Expand Down Expand Up @@ -981,6 +985,7 @@
2D1F7FD61E49DD18004D944B /* DispatchQueue+Hero.swift in Sources */,
2D1F7FCB1E49DD08004D944B /* HeroTargetState.swift in Sources */,
B17D888D1EF5A5500048D3E8 /* HeroTransition+UIViewControllerTransitioningDelegate.swift in Sources */,
B35264CF2454FEF300D33861 /* Locale+Hero.swift in Sources */,
B1D816E01EF5A5DF007B9776 /* HeroViewControllerDelegate.swift in Sources */,
B1193ABA1E525D12005B1C87 /* HeroAnimatorViewContext.swift in Sources */,
2D1F7FCA1E49DD08004D944B /* HeroPlugin.swift in Sources */,
Expand Down Expand Up @@ -1050,6 +1055,7 @@
A37D7B4D1E2C0C9300AC1959 /* CAMediaTimingFunction+Hero.swift in Sources */,
A37D7B5D1E2C0CBD00AC1959 /* HeroModifier.swift in Sources */,
B17D888C1EF5A5500048D3E8 /* HeroTransition+UIViewControllerTransitioningDelegate.swift in Sources */,
B35264CE2454FEF300D33861 /* Locale+Hero.swift in Sources */,
B1D816DF1EF5A5DF007B9776 /* HeroViewControllerDelegate.swift in Sources */,
B1193AB91E525D12005B1C87 /* HeroAnimatorViewContext.swift in Sources */,
A37D7B5B1E2C0CBD00AC1959 /* HeroDefaultAnimator.swift in Sources */,
Expand Down Expand Up @@ -1175,6 +1181,7 @@
2D1F7FC41E49DCB5004D944B /* Debug */ = {
isa = XCBuildConfiguration;
buildSettings = {
APPLICATION_EXTENSION_API_ONLY = YES;
CODE_SIGN_IDENTITY = "";
"CODE_SIGN_IDENTITY[sdk=appletvos*]" = "";
CURRENT_PROJECT_VERSION = 1;
Expand Down Expand Up @@ -1203,6 +1210,7 @@
2D1F7FC51E49DCB5004D944B /* Release */ = {
isa = XCBuildConfiguration;
buildSettings = {
APPLICATION_EXTENSION_API_ONLY = YES;
CODE_SIGN_IDENTITY = "";
CURRENT_PROJECT_VERSION = 1;
DEFINES_MODULE = YES;
Expand Down Expand Up @@ -1270,6 +1278,7 @@
A306D3BC1E1C7A2E00B6C23A /* Debug */ = {
isa = XCBuildConfiguration;
buildSettings = {
APPLICATION_EXTENSION_API_ONLY = YES;
CLANG_ENABLE_MODULES = YES;
CODE_SIGN_IDENTITY = "";
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "";
Expand Down Expand Up @@ -1298,6 +1307,7 @@
A306D3BD1E1C7A2E00B6C23A /* Release */ = {
isa = XCBuildConfiguration;
buildSettings = {
APPLICATION_EXTENSION_API_ONLY = YES;
CLANG_ENABLE_MODULES = YES;
CODE_SIGN_IDENTITY = "";
CURRENT_PROJECT_VERSION = 1;
Expand Down
24 changes: 24 additions & 0 deletions Sources/Extensions/Locale+Hero.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
//
// Locale+Hero.swift
// Hero
//
// Created by Joseph Mattiello on 4/25/20.
// Copyright © 2020 Luke Zhao. All rights reserved.
//

import Foundation

internal extension Locale {
internal static var isDeviceLanguageRightToLeft: Bool {
let currentLocale: Locale = Locale.current
guard let code: String = currentLocale.languageCode else {
return false
}
let direction: Locale.LanguageDirection = Locale.characterDirection(forLanguage: code)
return (direction == .rightToLeft)
}

internal static var isDeviceLanguageLeftToRight: Bool {
return !isDeviceLanguageRightToLeft
}
}
2 changes: 2 additions & 0 deletions Sources/Extensions/UIViewController+Hero.swift
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,9 @@ public extension HeroExtension where Base: UIViewController {
parentVC.present(next, animated: false, completion: completion)
}
} else {
#if TARGET_IS_EXTENSION
UIApplication.shared.keyWindow?.rootViewController = next
#endif
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions Sources/Preprocessors/CascadePreprocessor.swift
Original file line number Diff line number Diff line change
Expand Up @@ -74,11 +74,11 @@ public enum CascadeDirection {
}

public static var leadingToTrailing: CascadeDirection {
return UIApplication.shared.userInterfaceLayoutDirection == .leftToRight ? .leftToRight : .rightToLeft
return !Locale.isDeviceLanguageRightToLeft ? .leftToRight : .rightToLeft
}

public static var trailingToLeading: CascadeDirection {
return UIApplication.shared.userInterfaceLayoutDirection == .leftToRight ? .rightToLeft : .leftToRight
return !Locale.isDeviceLanguageRightToLeft ? .rightToLeft : .leftToRight
}

private func topToBottomComperator(lhs: UIView, rhs: UIView) -> Bool {
Expand Down
12 changes: 10 additions & 2 deletions Sources/Preprocessors/DefaultAnimationPreprocessor.swift
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,20 @@ public enum HeroDefaultAnimationType {
}
}

public static var leadingToTrailing: CascadeDirection {
return !Locale.isDeviceLanguageRightToLeft ? .leftToRight : .rightToLeft
}

public static var trailingToLeading: CascadeDirection {
return !Locale.isDeviceLanguageRightToLeft ? .rightToLeft : .leftToRight
}

public static var leading: Direction {
return UIApplication.shared.userInterfaceLayoutDirection == .leftToRight ? .left : .right
return !Locale.isDeviceLanguageRightToLeft ? .left : .right
}

public static var trailing: Direction {
return UIApplication.shared.userInterfaceLayoutDirection == .leftToRight ? .right : .left
return !Locale.isDeviceLanguageRightToLeft ? .right : .left
}
}

Expand Down
2 changes: 2 additions & 0 deletions Sources/Transition/HeroTransition+Complete.swift
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,9 @@ extension HeroTransition {
if isPresenting != finished, !inContainerController, transitionContext != nil {
// only happens when present a .overFullScreen VC
// bug: http://openradar.appspot.com/radar?id=5320103646199808
#if TARGET_IS_EXTENSION
UIApplication.shared.keyWindow?.addSubview(isPresenting ? fromView : toView)
#endif
}
}

Expand Down

0 comments on commit 800b9d9

Please sign in to comment.