Skip to content

Commit 65c64f7

Browse files
committed
Add fade animation option
1 parent 66401ca commit 65c64f7

File tree

6 files changed

+29
-6
lines changed

6 files changed

+29
-6
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ const App = () => {
6363
import { openBrowser } from "@swan-io/react-native-browser";
6464

6565
openBrowser("https://swan.io", {
66+
animationType: "", // "fade" | "slide" (default to "slide")
6667
dismissButtonStyle: "close", // "cancel" | "close" | "done" (default to "close")
6768
barTintColor: "#FFF", // in-app browser UI background color
6869
controlTintColor: "#000", // in-app browser buttons color

android/src/main/java/io/swan/rnbrowser/RNSwanBrowserModuleImpl.java

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,19 @@ protected static void open(final Activity activity,
3636
intentBuilder.setShowTitle(false);
3737
intentBuilder.setInstantAppsEnabled(false);
3838

39-
intentBuilder.setStartAnimations(activity,
40-
com.facebook.react.R.anim.catalyst_slide_up, io.swan.rnbrowser.R.anim.inert);
41-
intentBuilder.setExitAnimations(activity,
42-
io.swan.rnbrowser.R.anim.inert, com.facebook.react.R.anim.catalyst_slide_down);
39+
String animationType = options.getString("animationType");
40+
41+
if (animationType != null && animationType.equals("fade")) {
42+
intentBuilder.setStartAnimations(activity,
43+
com.facebook.react.R.anim.catalyst_fade_in, io.swan.rnbrowser.R.anim.inert);
44+
intentBuilder.setExitAnimations(activity,
45+
io.swan.rnbrowser.R.anim.inert, com.facebook.react.R.anim.catalyst_fade_out);
46+
} else {
47+
intentBuilder.setStartAnimations(activity,
48+
com.facebook.react.R.anim.catalyst_slide_up, io.swan.rnbrowser.R.anim.inert);
49+
intentBuilder.setExitAnimations(activity,
50+
io.swan.rnbrowser.R.anim.inert, com.facebook.react.R.anim.catalyst_slide_down);
51+
}
4352

4453
@ColorInt int blackColor = activity.getResources().getColor(android.R.color.black);
4554
CustomTabColorSchemeParams.Builder paramsBuilder = new CustomTabColorSchemeParams.Builder();

example/src/App.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ export const App = () => {
2323
let entry: StatusBarProps | undefined;
2424

2525
openBrowser("https://swan.io", {
26+
animationType: "slide",
2627
dismissButtonStyle: "close",
2728
barTintColor: "#FFF",
2829
controlTintColor: "#000",

ios/RNSwanBrowser.mm

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ - (void)open:(NSString *)url
6161
resolve:(RCTPromiseResolveBlock)resolve
6262
reject:(RCTPromiseRejectBlock)reject {
6363

64+
NSString *animationType = options.animationType();
6465
NSString *dismissButtonStyle = options.dismissButtonStyle();
6566
NSNumber *barTintColor = options.barTintColor().has_value() ? [NSNumber numberWithDouble:options.barTintColor().value()] : nil;
6667
NSNumber *controlTintColor = options.controlTintColor().has_value() ? [NSNumber numberWithDouble:options.controlTintColor().value()] : nil;
@@ -71,6 +72,7 @@ - (void)open:(NSString *)url
7172
resolve:(RCTPromiseResolveBlock)resolve
7273
reject:(RCTPromiseRejectBlock)reject) {
7374

75+
NSString *animationType = [options valueForKey:@"animationType"];
7476
NSString *dismissButtonStyle = [options valueForKey:@"dismissButtonStyle"];
7577
NSNumber *barTintColor = [options valueForKey:@"barTintColor"];
7678
NSNumber *controlTintColor = [options valueForKey:@"controlTintColor"];
@@ -102,7 +104,13 @@ - (void)open:(NSString *)url
102104
[_safariVC setPreferredControlTintColor:[RCTConvert UIColor:controlTintColor]];
103105
}
104106

105-
[_safariVC setModalPresentationStyle:UIModalPresentationPageSheet];
107+
if (animationType != nil && [animationType isEqualToString:@"fade"]) {
108+
[_safariVC setModalPresentationStyle:UIModalPresentationOverFullScreen];
109+
[_safariVC setModalTransitionStyle:UIModalTransitionStyleCrossDissolve];
110+
} else {
111+
[_safariVC setModalPresentationStyle:UIModalPresentationPageSheet];
112+
}
113+
106114
[RCTPresentedViewController() presentViewController:_safariVC animated:true completion:nil];
107115

108116
_safariVC.delegate = self;

src/NativeRNSwanBrowser.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import type { TurboModule } from "react-native";
22
import { TurboModuleRegistry } from "react-native";
33

44
type Options = {
5+
animationType?: string;
56
dismissButtonStyle?: string;
67
barTintColor?: number;
78
controlTintColor?: number;

src/index.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,11 @@ import NativeModule from "./NativeRNSwanBrowser";
33

44
const emitter = new NativeEventEmitter(NativeModule);
55

6+
export type AnimationType = "fade" | "slide";
67
export type DismissButtonStyle = "cancel" | "close" | "done";
78

89
export type Options = {
10+
animationType?: AnimationType;
911
dismissButtonStyle?: DismissButtonStyle;
1012
barTintColor?: string;
1113
controlTintColor?: string;
@@ -24,11 +26,12 @@ const convertColorToNumber = (
2426
};
2527

2628
export const openBrowser = (url: string, options: Options): Promise<void> => {
27-
const { dismissButtonStyle, onOpen, onClose } = options;
29+
const { animationType, dismissButtonStyle, onOpen, onClose } = options;
2830
const barTintColor = convertColorToNumber(options.barTintColor);
2931
const controlTintColor = convertColorToNumber(options.controlTintColor);
3032

3133
return NativeModule.open(url, {
34+
...(animationType != null && { animationType }),
3235
...(dismissButtonStyle != null && { dismissButtonStyle }),
3336
...(barTintColor != null && { barTintColor }),
3437
...(controlTintColor != null && { controlTintColor }),

0 commit comments

Comments
 (0)