This repository has been archived by the owner on Oct 20, 2022. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 18
/
Copy pathindex.js
114 lines (89 loc) · 3.72 KB
/
index.js
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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
import { NativeEventEmitter, NativeModules, processColor, Platform } from 'react-native'
const RNTurbolinksManager = NativeModules.RNTurbolinksManager || NativeModules.RNTurbolinksModule
const RNTurbolinksManagerEmitter = new NativeEventEmitter(RNTurbolinksManager)
const resolveAssetSource = require('react-native/Libraries/Image/resolveAssetSource')
class Turbolinks {
static Constants = {
ErrorCode: RNTurbolinksManager.ErrorCode,
Action: RNTurbolinksManager.Action
}
static startSingleScreenApp(route, options = {}) {
this._processRoute(route)
this._processNavBarStyle(options.navBarStyle)
RNTurbolinksManager.startSingleScreenApp(route, options)
}
static startSplitScreenApp(primaryComponent, secondaryRoute, options = {}) {
this._processRoute(secondaryRoute)
this._processNavBarStyle(options.navBarStyle)
RNTurbolinksManager.startSplitScreenApp(primaryComponent, secondaryRoute, options)
}
static reloadVisitable() {
RNTurbolinksManager.reloadVisitable()
}
static reloadSession() {
RNTurbolinksManager.reloadSession()
}
static removeAllCookies() {
RNTurbolinksManager.removeAllCookies()
return new Promise((resolve) => setTimeout(() => resolve(), 1000))
}
static dismiss(animated = true) {
RNTurbolinksManager.dismiss(animated)
return new Promise((resolve) => setTimeout(() => resolve(), 1000))
}
static popToRoot(animated = true) {
RNTurbolinksManager.popToRoot(animated)
return new Promise((resolve) => setTimeout(() => resolve(), 1000))
}
static back(animated = true) {
RNTurbolinksManager.back(animated)
return new Promise((resolve) => setTimeout(() => resolve(), 1000))
}
static visit(route) {
this._processRoute(route)
RNTurbolinksManager.visit(route)
}
static replaceWith(route) {
this._processRoute(route)
RNTurbolinksManager.replaceWith(route)
}
static renderTitle(title, subtitle = null) {
RNTurbolinksManager.renderTitle(title, subtitle)
}
static renderActions(actions) {
RNTurbolinksManager.renderActions(actions)
}
static renderNavBarStyle(style) {
this._processNavBarStyle(style)
RNTurbolinksManager.renderNavBarStyle(style)
}
static injectJavaScript(script) {
RNTurbolinksManager.injectJavaScript(script)
return new Promise((resolve) => setTimeout(() => resolve(), 1000))
}
static addEventListener(eventName, callback) {
RNTurbolinksManagerEmitter.addListener(eventName, callback)
}
static removeEventListener(eventName, callback) {
RNTurbolinksManagerEmitter.removeListener(eventName, callback)
}
static _processNavBarStyle(style) {
if (style && style.barTintColor) style.barTintColor = processColor(style.barTintColor)
if (style && style.tintColor) style.tintColor = processColor(style.tintColor)
if (style && style.titleTextColor) style.titleTextColor = processColor(style.titleTextColor)
if (style && style.subtitleTextColor) style.subtitleTextColor = processColor(style.subtitleTextColor)
if (style && style.menuIcon) style.menuIcon = resolveAssetSource(style.menuIcon)
}
static _processRoute(route) {
if (route.titleImage) route.titleImage = resolveAssetSource(route.titleImage)
if (route.leftButtonIcon) route.leftButtonIcon = resolveAssetSource(route.leftButtonIcon)
if (route.rightButtonIcon) route.rightButtonIcon = resolveAssetSource(route.rightButtonIcon)
if (route.navIcon) route.navIcon = resolveAssetSource(route.navIcon)
if (route.actions) route.actions = resolveAssetSourceActions(route.actions)
function resolveAssetSourceActions(actions) {
actions.filter(act => act.icon).forEach(act => { act.icon = resolveAssetSource(act.icon) })
return actions
}
}
}
module.exports = Turbolinks;