Skip to content

Commit 8ffa31b

Browse files
committed
WIP
1 parent 760af0f commit 8ffa31b

File tree

14 files changed

+106
-171
lines changed

14 files changed

+106
-171
lines changed

README.md

Lines changed: 20 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -30,21 +30,26 @@ import { Button, SafeAreaView } from "react-native";
3030
import parseUrl from "url-parse";
3131

3232
const App = () => {
33-
const handleOnPress = useCallback(() => {
34-
openBrowser("https://swan.io", {
35-
onClose: (url) => {
36-
if (url) {
37-
const { protocol, host, query } = parseUrl(url, true);
38-
const origin = `${protocol}//${host}`;
39-
40-
if (origin === "com.company.myapp://close") {
41-
console.log(JSON.stringify(query, null, 2));
42-
}
33+
useEffect(() => {
34+
const subscription = Linking.addListener(
35+
"url",
36+
({ url }: { url: string }) => {
37+
const { protocol, host, query } = parseUrl(url, true);
38+
const origin = `${protocol}//${host}`;
39+
40+
if (origin === "com.company.myapp://close") {
41+
console.log(JSON.stringify(query, null, 2));
4342
}
4443
},
45-
}).catch((error) => {
46-
console.error(error);
47-
});
44+
);
45+
46+
return () => {
47+
subscription.remove();
48+
};
49+
}, []);
50+
51+
const handleOnPress = useCallback(() => {
52+
openBrowser("https://swan.io").catch((error) => console.error(error));
4853
}, []);
4954

5055
return (
@@ -57,7 +62,7 @@ const App = () => {
5762

5863
## API
5964

60-
### openBrowser(url: string, options: Options)
65+
### openBrowser(url: string, options?: Options)
6166

6267
```tsx
6368
import { openBrowser } from "@swan-io/react-native-browser";
@@ -67,14 +72,6 @@ openBrowser("https://swan.io", {
6772
dismissButtonStyle: "close", // "cancel" | "close" | "done" (default to "close")
6873
barTintColor: "#FFF", // in-app browser UI background color
6974
controlTintColor: "#000", // in-app browser buttons color
70-
onOpen: () => {
71-
// fired on browser opened
72-
// useful to switch the StatusBar color, for example
73-
},
74-
onClose: (url) => {
75-
// fired on browser closed
76-
// url will be defined if the browser has been closed via deeplink
77-
},
7875
}).catch((error) => {
7976
console.error(error);
8077
});
@@ -85,7 +82,7 @@ openBrowser("https://swan.io", {
8582
8683
## Handle deeplinks
8784

88-
In order to receive deeplink on browser close event, you have to setup them first. We **highly** recommand defining a custom schema + url for this specific task. For example, `com.company.myapp://close`.
85+
In order to receive deeplink on browser close, you have to setup them first. We **highly** recommand defining a custom schema + url for this specific task. For example, `com.company.myapp://close`.
8986

9087
### On iOS
9188

RNSwanBrowser.podspec

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,16 @@ Pod::Spec.new do |s|
1111
s.author = package["author"]
1212
s.homepage = package["homepage"]
1313

14-
s.platforms = { :ios => "15.1", :tvos => "15.1" }
14+
s.platforms = { :ios => "13.4", :tvos => "13.4" }
1515
s.requires_arc = true
1616

17-
s.frameworks = "SafariServices"
1817
s.source = { :git => package["repository"]["url"], :tag => s.version }
1918
s.source_files = "ios/**/*.{h,m,mm}"
19+
s.frameworks = "SafariServices"
2020

21-
install_modules_dependencies(s)
21+
if ENV['RCT_NEW_ARCH_ENABLED'] == '1' then
22+
install_modules_dependencies(s)
23+
else
24+
s.dependency "React-Core"
25+
end
2226
end

android/build.gradle

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ buildscript {
77
gradlePluginPortal()
88
}
99
dependencies {
10-
classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:${safeExtGet("kotlinVersion", "1.8.0")}")
11-
classpath("com.android.tools.build:gradle:7.3.1")
10+
classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:${safeExtGet("kotlinVersion", "1.9.22")}")
11+
classpath("com.android.tools.build:gradle:8.2.1")
1212
}
1313
}
1414

@@ -24,20 +24,13 @@ if (isNewArchitectureEnabled()) {
2424
}
2525

2626
android {
27+
namespace "io.swan.rnbrowser"
28+
2729
buildToolsVersion safeExtGet("buildToolsVersion", "34.0.0")
2830
compileSdkVersion safeExtGet("compileSdkVersion", 34)
2931

30-
if (project.android.hasProperty("namespace")) {
31-
namespace "io.swan.rnbrowser"
32-
33-
buildFeatures {
34-
buildConfig true
35-
}
36-
sourceSets {
37-
main {
38-
manifest.srcFile "src/main/AndroidManifestNew.xml"
39-
}
40-
}
32+
buildFeatures {
33+
buildConfig true
4134
}
4235
defaultConfig {
4336
buildConfigField("boolean", "IS_NEW_ARCHITECTURE_ENABLED", isNewArchitectureEnabled().toString())

android/src/main/AndroidManifest.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<?xml version="1.0" encoding="utf-8"?>
2-
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="io.swan.rnbrowser">
2+
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
33
<queries>
44
<intent>
55
<action android:name="android.support.customtabs.action.CustomTabsService" />

android/src/main/AndroidManifestNew.xml

Lines changed: 0 additions & 8 deletions
This file was deleted.

example/Gemfile.lock

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ GEM
7979
mutex_m
8080
i18n (1.14.7)
8181
concurrent-ruby (~> 1.0)
82-
json (2.13.1)
82+
json (2.13.2)
8383
logger (1.7.0)
8484
minitest (5.25.5)
8585
molinillo (0.8.0)

example/ios/Podfile.lock

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2456,7 +2456,7 @@ SPEC CHECKSUMS:
24562456
ReactAppDependencyProvider: 8df342c127fd0c1e30e8b9f71ff814c22414a7c0
24572457
ReactCodegen: 439c427ccc115d71d16cc84256e5fbdc7fcef57a
24582458
ReactCommon: 592ef441605638b95e533653259254b4bd35ff4f
2459-
RNSwanBrowser: 855f0e20b2acd92fcb11fd3a4757dfee64581a93
2459+
RNSwanBrowser: 48cdb9a43eb0697602371982ecceffdb6566095d
24602460
SocketRocket: d4aabe649be1e368d1318fdf28a022d714d65748
24612461
Yoga: a742cc68e8366fcfc681808162492bc0aa7a9498
24622462

example/src/App.tsx

Lines changed: 20 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,6 @@
11
import { openBrowser } from "@swan-io/react-native-browser";
2-
import * as React from "react";
3-
import {
4-
type StatusBarProps,
5-
Button,
6-
Platform,
7-
SafeAreaView,
8-
StatusBar,
9-
StyleSheet,
10-
} from "react-native";
2+
import { useCallback, useEffect } from "react";
3+
import { Alert, Button, Linking, SafeAreaView, StyleSheet } from "react-native";
114
import parseUrl from "url-parse";
125

136
const styles = StyleSheet.create({
@@ -19,37 +12,30 @@ const styles = StyleSheet.create({
1912
});
2013

2114
export const App = () => {
22-
const handleOnPress = React.useCallback(() => {
23-
let entry: StatusBarProps | undefined;
15+
useEffect(() => {
16+
const subscription = Linking.addListener(
17+
"url",
18+
({ url }: { url: string }) => {
19+
const { protocol, host, query } = parseUrl(url, true);
20+
const origin = `${protocol}//${host}`;
2421

22+
if (origin === "io.swan.rnbrowserexample://close") {
23+
Alert.alert("Deeplink received", JSON.stringify(query, null, 2));
24+
}
25+
},
26+
);
27+
28+
return () => {
29+
subscription.remove();
30+
};
31+
}, []);
32+
33+
const handleOnPress = useCallback(() => {
2534
openBrowser("https://swan.io", {
2635
animationType: "slide",
2736
dismissButtonStyle: "close",
2837
barTintColor: "#FFF",
2938
controlTintColor: "#000",
30-
onOpen: () => {
31-
entry = StatusBar.pushStackEntry({
32-
animated: true,
33-
barStyle:
34-
Platform.OS === "ios" && Number.parseInt(Platform.Version, 10) >= 13
35-
? "light-content"
36-
: "dark-content",
37-
});
38-
},
39-
onClose: (url) => {
40-
if (entry) {
41-
StatusBar.popStackEntry(entry);
42-
}
43-
44-
if (url) {
45-
const { protocol, host, query } = parseUrl(url, true);
46-
const origin = `${protocol}//${host}`;
47-
48-
if (origin === "io.swan.rnbrowserexample://close") {
49-
console.log(JSON.stringify(query, null, 2));
50-
}
51-
}
52-
},
5339
}).catch((error) => {
5440
console.error(error);
5541
});

example/yarn.lock

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1868,9 +1868,9 @@ babel-plugin-transform-flow-enums@^0.0.2:
18681868
"@babel/plugin-syntax-flow" "^7.12.1"
18691869

18701870
babel-preset-current-node-syntax@^1.0.0:
1871-
version "1.1.0"
1872-
resolved "https://registry.yarnpkg.com/babel-preset-current-node-syntax/-/babel-preset-current-node-syntax-1.1.0.tgz#9a929eafece419612ef4ae4f60b1862ebad8ef30"
1873-
integrity sha512-ldYss8SbBlWva1bs28q78Ju5Zq1F+8BrqBZZ0VFhLBvhh6lCpC2o3gDJi/5DRLs9FgYZCnmPYIVFU4lRXCkyUw==
1871+
version "1.1.1"
1872+
resolved "https://registry.yarnpkg.com/babel-preset-current-node-syntax/-/babel-preset-current-node-syntax-1.1.1.tgz#204c610030f7e74d4cb1ad7d0ff3c044abf48688"
1873+
integrity sha512-23fWKohMTvS5s0wwJKycOe0dBdCwQ6+iiLaNR9zy8P13mtFRFM9qLLX6HJX5DL2pi/FNDf3fCQHM4FIMoHH/7w==
18741874
dependencies:
18751875
"@babel/plugin-syntax-async-generators" "^7.8.4"
18761876
"@babel/plugin-syntax-bigint" "^7.8.3"
@@ -3151,12 +3151,12 @@ kleur@^3.0.3:
31513151
integrity sha512-eTIzlVOSUR+JxdDFepEYcBMtZ9Qqdef+rnzWdRZuMbOywu5tO2w2N7rqjoANZ5k9vywhL6Br1VRjUIgTQx4E8w==
31523152

31533153
launch-editor@^2.9.1:
3154-
version "2.10.0"
3155-
resolved "https://registry.yarnpkg.com/launch-editor/-/launch-editor-2.10.0.tgz#5ca3edfcb9667df1e8721310f3a40f1127d4bc42"
3156-
integrity sha512-D7dBRJo/qcGX9xlvt/6wUYzQxjh5G1RvZPgPv8vi4KRU99DVQL/oW7tnVOCCTm2HGeo3C5HvGE5Yrh6UBoZ0vA==
3154+
version "2.11.0"
3155+
resolved "https://registry.yarnpkg.com/launch-editor/-/launch-editor-2.11.0.tgz#1ec15b3ed249b04763453661a9785428b38d5b33"
3156+
integrity sha512-R/PIF14L6e2eHkhvQPu7jDRCr0msfCYCxbYiLgkkAGi0dVPWuM+RrsPu0a5dpuNe0KWGL3jpAkOlv53xGfPheQ==
31573157
dependencies:
3158-
picocolors "^1.0.0"
3159-
shell-quote "^1.8.1"
3158+
picocolors "^1.1.1"
3159+
shell-quote "^1.8.3"
31603160

31613161
leven@^3.1.0:
31623162
version "3.1.0"
@@ -3810,7 +3810,7 @@ path-to-regexp@3.3.0:
38103810
resolved "https://registry.yarnpkg.com/path-to-regexp/-/path-to-regexp-3.3.0.tgz#f7f31d32e8518c2660862b644414b6d5c63a611b"
38113811
integrity sha512-qyCH421YQPS2WFDxDjftfc1ZR5WKQzVzqsp4n9M2kQhVOo/ByahFoUNJfl58kOcEGfQ//7weFTDhm+ss8Ecxgw==
38123812

3813-
picocolors@^1.0.0, picocolors@^1.1.1:
3813+
picocolors@^1.1.1:
38143814
version "1.1.1"
38153815
resolved "https://registry.yarnpkg.com/picocolors/-/picocolors-1.1.1.tgz#3d321af3eab939b083c8f929a1d12cda81c26b6b"
38163816
integrity sha512-xceH2snhtb5M9liqDsmEw56le376mTZkEX/jEb/RxNFyegNul7eNslCXP9FDj/Lcu0X8KEyMceP2ntpaHrDEVA==
@@ -4251,7 +4251,7 @@ shebang-regex@^3.0.0:
42514251
resolved "https://registry.yarnpkg.com/shebang-regex/-/shebang-regex-3.0.0.tgz#ae16f1644d873ecad843b0307b143362d4c42172"
42524252
integrity sha512-7++dFhtcx3353uBaq8DDR4NuxBetBzC7ZQOhmTQInHEd6bSrXdiEyzCvG07Z44UYdLShWUyXt5M/yhz8ekcb1A==
42534253

4254-
shell-quote@^1.6.1, shell-quote@^1.8.1:
4254+
shell-quote@^1.6.1, shell-quote@^1.8.3:
42554255
version "1.8.3"
42564256
resolved "https://registry.yarnpkg.com/shell-quote/-/shell-quote-1.8.3.tgz#55e40ef33cf5c689902353a3d8cd1a6725f08b4b"
42574257
integrity sha512-ObmnIF4hXNg1BqhnHmgbDETF8dLPCggZWBjkQfhZpbszZnYur5DUljTcCHii5LC3J5E0yeO/1LIMyH+UvHQgyw==

ios/RNSwanBrowser.h

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,15 @@
1+
#ifdef RCT_NEW_ARCH_ENABLED
2+
13
#import <RNSwanBrowserSpec/RNSwanBrowserSpec.h>
24

3-
NS_ASSUME_NONNULL_BEGIN
5+
@interface RNSwanBrowser : NSObject <NativeRNSwanBrowserSpec>
6+
@end
7+
8+
#else
49

5-
@interface RNSwanBrowser : NativeRNSwanBrowserSpecBase <NativeRNSwanBrowserSpec>
10+
#import <React/RCTBridgeModule.h>
611

12+
@interface RNSwanBrowser : NSObject <RCTBridgeModule>
713
@end
814

9-
NS_ASSUME_NONNULL_END
15+
#endif

0 commit comments

Comments
 (0)