Skip to content

Commit 6ef7e38

Browse files
authored
[Patch 1.0.1] Add support for navigation/tab view controllers (#67)
* Add support for navigation/tab view controllers * bump: patch + changelog entry
1 parent 01f69f0 commit 6ef7e38

File tree

20 files changed

+194
-61
lines changed

20 files changed

+194
-61
lines changed

.github/actions/install-cocoapods/action.yml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,5 +20,10 @@ runs:
2020
env:
2121
NO_FLIPPER: "1"
2222
run: |
23-
yarn pod-install sample/ios
23+
ROOT=$(pwd)
24+
cd sample
25+
bundle install
26+
cd ios
27+
NO_FLIPPER=1 bundle exec pod install
28+
cd $ROOT
2429

.github/actions/setup-simulator/action.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,5 @@ runs:
1212
xcrun simctl list runtimes
1313
xcrun simctl list devicetypes
1414
xcrun simctl delete all
15-
CURRENT_SIMULATOR_UUID=$(xcrun simctl create TestDevice "iPhone 14 Pro Max")
15+
CURRENT_SIMULATOR_UUID=$(xcrun simctl create TestDevice "iPhone 15 Pro")
1616
echo "CURRENT_SIMULATOR_UUID=$CURRENT_SIMULATOR_UUID" >> $GITHUB_ENV

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,3 +92,6 @@ modules/@shopify/checkout-sheet-kit/android/gradlew.bat
9292
# Sample bundle
9393
**/index.android.bundle
9494
.xcode.env.local
95+
96+
# Local gems
97+
sample/vendor

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
# Changelog
22

3+
## 1.0.1 - February 20, 2024
4+
5+
- Adds support for view controllers other than the `rootViewController`. This
6+
allows triggering the Checkout Sheet from modals and formSheets etc.
7+
38
## 1.0.0 - January 31, 2024
49

510
ShopifyCheckoutSheetKit is now generally available for

metro.config.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,11 @@ const config = mergeConfig(getDefaultConfig(__dirname), {
3131
extraNodeModules: {
3232
react: path.resolve(sample, 'node_modules', 'react'),
3333
'react-native': path.resolve(sample, 'node_modules', 'react-native'),
34+
'react-native-gesture-handler': path.resolve(
35+
root,
36+
'node_modules',
37+
'react-native-gesture-handler',
38+
),
3439
'@shopify/checkout-sheet-kit': path.resolve(
3540
root,
3641
'modules',

modules/@shopify/checkout-sheet-kit/ios/ShopifyCheckoutSheetKit.swift

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -100,12 +100,34 @@ class RCTShopifyCheckoutSheetKit: RCTEventEmitter, CheckoutDelegate {
100100
]
101101
}
102102

103+
static func getRootViewController() -> UIViewController? {
104+
return (UIApplication.shared.connectedScenes
105+
.first(where: { $0.activationState == .foregroundActive }) as? UIWindowScene)?.windows
106+
.first(where: { $0.isKeyWindow })?.rootViewController
107+
}
108+
109+
func getCurrentViewController(_ controller: UIViewController? = getRootViewController()) -> UIViewController? {
110+
if let presentedViewController = controller?.presentedViewController {
111+
return getCurrentViewController(presentedViewController)
112+
}
113+
114+
if let navigationController = controller as? UINavigationController {
115+
return getCurrentViewController(navigationController.visibleViewController)
116+
}
117+
118+
if let tabBarController = controller as? UITabBarController {
119+
if let selectedViewController = tabBarController.selectedViewController {
120+
return getCurrentViewController(selectedViewController)
121+
}
122+
}
123+
124+
return controller
125+
}
126+
103127
@objc func present(_ checkoutURL: String) {
104128
DispatchQueue.main.async {
105-
let sharedDelegate = UIApplication.shared.delegate
106-
107-
if let url = URL(string: checkoutURL), let rootViewController = sharedDelegate?.window??.rootViewController {
108-
ShopifyCheckoutSheetKit.present(checkout: url, from: rootViewController, delegate: self)
129+
if let url = URL(string: checkoutURL), let viewController = self.getCurrentViewController() {
130+
ShopifyCheckoutSheetKit.present(checkout: url, from: viewController, delegate: self)
109131
}
110132
}
111133
}

modules/@shopify/checkout-sheet-kit/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "@shopify/checkout-sheet-kit",
33
"license": "MIT",
4-
"version": "1.0.0",
4+
"version": "1.0.1",
55
"main": "lib/commonjs/index.js",
66
"types": "src/index.ts",
77
"source": "src/index.ts",

package.json

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
"clean": "watchman watch-del .",
1919
"sample": "yarn workspace sample",
2020
"module": "yarn workspace @shopify/checkout-sheet-kit",
21-
"pod-install": "NO_FLIPPER=1 pod-install",
21+
"pod-install": "(cd sample/ios && NO_FLIPPER=1 bundle exec pod install)",
2222
"snapshot": "./scripts/create_snapshot",
2323
"turbo": "turbo",
2424
"test": "jest"
@@ -38,11 +38,11 @@
3838
"babel-jest": "^29.7.0",
3939
"eslint": "^8.19.0",
4040
"jest": "^29.2.1",
41-
"pod-install": "^0.2.0",
4241
"prettier": "^2.4.1",
4342
"react": "^18.2.0",
4443
"react-native": "0.72.8",
4544
"react-native-dotenv": "^3.4.9",
45+
"react-native-gesture-handler": "^2.15.0",
4646
"react-native-gradle-plugin": "^0.71.19",
4747
"react-test-renderer": "18.2.0",
4848
"ts-jest": "^29.1.1",
@@ -75,8 +75,5 @@
7575
"no-console": "error"
7676
}
7777
},
78-
"packageManager": "[email protected]",
79-
"dependencies": {
80-
"react-native-gesture-handler": "^2.14.0"
81-
}
78+
"packageManager": "[email protected]"
8279
}

sample/Gemfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,5 @@ source 'https://rubygems.org'
33
# You may use http://rbenv.org/ or https://rvm.io/ to install and use this version
44
ruby ">= 2.6.10"
55

6-
gem 'cocoapods', '~> 1.13'
6+
gem 'cocoapods', '~> 1.15.2'
77
gem 'activesupport', '>= 6.1.7.3', '< 7.1.0'

sample/Gemfile.lock

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,29 @@
11
GEM
22
remote: https://rubygems.org/
33
specs:
4-
CFPropertyList (3.0.6)
4+
CFPropertyList (3.0.7)
5+
base64
6+
nkf
57
rexml
68
activesupport (7.0.8)
79
concurrent-ruby (~> 1.0, >= 1.0.2)
810
i18n (>= 1.6, < 2)
911
minitest (>= 5.1)
1012
tzinfo (~> 2.0)
11-
addressable (2.8.5)
13+
addressable (2.8.6)
1214
public_suffix (>= 2.0.2, < 6.0)
1315
algoliasearch (1.27.5)
1416
httpclient (~> 2.8, >= 2.8.3)
1517
json (>= 1.5.1)
1618
atomos (0.1.3)
19+
base64 (0.2.0)
1720
claide (1.1.0)
18-
cocoapods (1.14.2)
21+
cocoapods (1.15.2)
1922
addressable (~> 2.8)
2023
claide (>= 1.0.2, < 2.0)
21-
cocoapods-core (= 1.14.2)
24+
cocoapods-core (= 1.15.2)
2225
cocoapods-deintegrate (>= 1.0.3, < 2.0)
23-
cocoapods-downloader (>= 2.0)
26+
cocoapods-downloader (>= 2.1, < 3.0)
2427
cocoapods-plugins (>= 1.0.0, < 2.0)
2528
cocoapods-search (>= 1.0.0, < 2.0)
2629
cocoapods-trunk (>= 1.6.0, < 2.0)
@@ -33,7 +36,7 @@ GEM
3336
nap (~> 1.0)
3437
ruby-macho (>= 2.3.0, < 3.0)
3538
xcodeproj (>= 1.23.0, < 2.0)
36-
cocoapods-core (1.14.2)
39+
cocoapods-core (1.15.2)
3740
activesupport (>= 5.0, < 8)
3841
addressable (~> 2.8)
3942
algoliasearch (~> 1.0)
@@ -44,7 +47,7 @@ GEM
4447
public_suffix (~> 4.0)
4548
typhoeus (~> 1.0)
4649
cocoapods-deintegrate (1.0.5)
47-
cocoapods-downloader (2.0)
50+
cocoapods-downloader (2.1)
4851
cocoapods-plugins (1.0.0)
4952
nap
5053
cocoapods-search (1.0.1)
@@ -64,20 +67,21 @@ GEM
6467
httpclient (2.8.3)
6568
i18n (1.14.1)
6669
concurrent-ruby (~> 1.0)
67-
json (2.6.3)
70+
json (2.7.1)
6871
minitest (5.20.0)
6972
molinillo (0.8.0)
7073
nanaimo (0.3.0)
7174
nap (1.1.0)
7275
netrc (0.11.0)
76+
nkf (0.2.0)
7377
public_suffix (4.0.7)
7478
rexml (3.2.6)
7579
ruby-macho (2.5.1)
76-
typhoeus (1.4.0)
80+
typhoeus (1.4.1)
7781
ethon (>= 0.9.0)
7882
tzinfo (2.0.6)
7983
concurrent-ruby (~> 1.0)
80-
xcodeproj (1.23.0)
84+
xcodeproj (1.24.0)
8185
CFPropertyList (>= 2.3.3, < 4.0)
8286
atomos (~> 0.1.3)
8387
claide (>= 1.0.2, < 2.0)
@@ -90,7 +94,7 @@ PLATFORMS
9094

9195
DEPENDENCIES
9296
activesupport (>= 6.1.7.3, < 7.1.0)
93-
cocoapods (~> 1.13)
97+
cocoapods (~> 1.15.2)
9498

9599
RUBY VERSION
96100
ruby 3.1.2p20

0 commit comments

Comments
 (0)