This repository has been archived by the owner on Aug 8, 2022. It is now read-only.
forked from droibit/react-native-custom-tabs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.ts
95 lines (82 loc) · 2.47 KB
/
index.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
import { NativeModules } from "react-native";
interface ICustomTabsManager {
openURL(url: string, option: Record<string, unknown>): Promise<boolean>;
}
const CustomTabsManager = NativeModules.CustomTabsManager as ICustomTabsManager;
export type Animations = {
startEnter: string;
startExit: string;
endEnter: string;
endExit: string;
};
/**
* Start and exit animations of Custom Tabs.
* Slide in from left at start, Slide out to right at exit.
*/
export const ANIMATIONS_SLIDE: Animations = {
startEnter: "slide_in_right",
startExit: "slide_out_left",
endEnter: "android:anim/slide_in_left",
endExit: "android:anim/slide_out_right",
};
/**
* Start and exit animations of Custom Tabs.
* Fade in at start, Fade out at exit.
*/
export const ANIMATIONS_FADE: Animations = {
startEnter: "android:anim/fade_in",
startExit: "android:anim/fade_out",
endEnter: "android:anim/fade_in",
endExit: "android:anim/fade_out",
};
/**
* Options to customize the look & feel of Custom Tabs.
*/
export type TabOption = {
/**
* the Toolbar color.
* Supported formats are: #RRGGBB, #AARRGGBB, etc.
*
* {@link http://d.android.com/reference/android/graphics/Color.html#parseColor(java.lang.String) Color.parseColor(String)}
*/
toolbarColor?: string | null;
/**
* Enables the url bar to hide as the user scrolls down on the page.
*/
enableUrlBarHiding?: boolean | null;
/**
* Sets whether the title should be shown in the custom tab.
*/
showPageTitle?: boolean | null;
/**
* Whether to add a default shared items of the menu.
*/
enableDefaultShare?: boolean | null;
/**
* Sets the exit and start animations.
*
* Each property needs to be an Android animation resource ID,
* e.g. 'com.github.droibit.android.reactnative.customtabs.example:anim/slide_out_bottom'
*
* @see ANIMATIONS_FADE
* @see ANIMATIONS_SLIDE
*/
animations?: Animations | null;
/**
* Sets any custom headers that should be used.
*/
headers?: Record<string, unknown> | null;
/**
* Workaround that Custom Tabs doesn't close on redirecting back to app scheme.
*/
forceCloseOnRedirection?: boolean | null;
};
/**
* Opens the URL on a Custom Tab. If Chrome is not installed, opens the URL in other browser.
*
* @param url the Uri to be opened.
* @param option the Option to customize Custom Tabs of look & feel.
*/
export function openURL(url: string, option: TabOption = {}): Promise<boolean> {
return CustomTabsManager.openURL(url, option);
}