-
-
Notifications
You must be signed in to change notification settings - Fork 538
/
Copy pathScreenViewManager.kt
296 lines (258 loc) · 9.83 KB
/
ScreenViewManager.kt
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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
package com.swmansion.rnscreens
import com.facebook.react.bridge.JSApplicationIllegalArgumentException
import com.facebook.react.bridge.ReadableMap
import com.facebook.react.common.MapBuilder
import com.facebook.react.module.annotations.ReactModule
import com.facebook.react.uimanager.ReactStylesDiffMap
import com.facebook.react.uimanager.StateWrapper
import com.facebook.react.uimanager.ThemedReactContext
import com.facebook.react.uimanager.ViewGroupManager
import com.facebook.react.uimanager.ViewManagerDelegate
import com.facebook.react.uimanager.annotations.ReactProp
import com.facebook.react.viewmanagers.RNSScreenManagerDelegate
import com.facebook.react.viewmanagers.RNSScreenManagerInterface
import com.swmansion.rnscreens.events.HeaderBackButtonClickedEvent
import com.swmansion.rnscreens.events.HeaderHeightChangeEvent
import com.swmansion.rnscreens.events.ScreenAppearEvent
import com.swmansion.rnscreens.events.ScreenDisappearEvent
import com.swmansion.rnscreens.events.ScreenDismissedEvent
import com.swmansion.rnscreens.events.ScreenTransitionProgressEvent
import com.swmansion.rnscreens.events.ScreenWillAppearEvent
import com.swmansion.rnscreens.events.ScreenWillDisappearEvent
@ReactModule(name = ScreenViewManager.REACT_CLASS)
open class ScreenViewManager :
ViewGroupManager<Screen>(),
RNSScreenManagerInterface<Screen> {
private val delegate: ViewManagerDelegate<Screen>
init {
delegate = RNSScreenManagerDelegate<Screen, ScreenViewManager>(this)
}
override fun getName() = REACT_CLASS
override fun createViewInstance(reactContext: ThemedReactContext) = Screen(reactContext)
override fun setActivityState(
view: Screen,
activityState: Float,
) {
setActivityState(view, activityState.toInt())
}
override fun updateState(
view: Screen,
props: ReactStylesDiffMap?,
stateWrapper: StateWrapper?,
): Any? {
if (BuildConfig.IS_NEW_ARCHITECTURE_ENABLED) {
// fabricViewStateManager should never be null in Fabric. The null check is only for Paper's empty impl.
view.fabricViewStateManager?.setStateWrapper(stateWrapper)
}
return super.updateState(view, props, stateWrapper)
}
@ReactProp(name = "activityState")
fun setActivityState(
view: Screen,
activityState: Int,
) {
if (activityState == -1) {
// Null will be provided when activityState is set as an animated value and we change
// it from JS to be a plain value (non animated).
// In case when null is received, we want to ignore such value and not make
// any updates as the actual non-null value will follow immediately.
return
}
when (activityState) {
0 -> view.setActivityState(Screen.ActivityState.INACTIVE)
1 -> view.setActivityState(Screen.ActivityState.TRANSITIONING_OR_BELOW_TOP)
2 -> view.setActivityState(Screen.ActivityState.ON_TOP)
}
}
@ReactProp(name = "stackPresentation")
override fun setStackPresentation(
view: Screen,
presentation: String?,
) {
view.stackPresentation =
when (presentation) {
"push" -> Screen.StackPresentation.PUSH
"modal", "containedModal", "fullScreenModal", "formSheet" ->
Screen.StackPresentation.MODAL
"transparentModal", "containedTransparentModal" ->
Screen.StackPresentation.TRANSPARENT_MODAL
else -> throw JSApplicationIllegalArgumentException("Unknown presentation type $presentation")
}
}
@ReactProp(name = "stackAnimation")
override fun setStackAnimation(
view: Screen,
animation: String?,
) {
view.stackAnimation =
when (animation) {
null, "default", "flip", "simple_push" -> Screen.StackAnimation.DEFAULT
"none" -> Screen.StackAnimation.NONE
"fade" -> Screen.StackAnimation.FADE
"slide_from_right" -> Screen.StackAnimation.SLIDE_FROM_RIGHT
"slide_from_left" -> Screen.StackAnimation.SLIDE_FROM_LEFT
"slide_from_bottom" -> Screen.StackAnimation.SLIDE_FROM_BOTTOM
"fade_from_bottom" -> Screen.StackAnimation.FADE_FROM_BOTTOM
"ios" -> Screen.StackAnimation.IOS
else -> throw JSApplicationIllegalArgumentException("Unknown animation type $animation")
}
}
@ReactProp(name = "gestureEnabled", defaultBoolean = true)
override fun setGestureEnabled(
view: Screen,
gestureEnabled: Boolean,
) {
view.isGestureEnabled = gestureEnabled
}
@ReactProp(name = "replaceAnimation")
override fun setReplaceAnimation(
view: Screen,
animation: String?,
) {
view.replaceAnimation =
when (animation) {
null, "pop" -> Screen.ReplaceAnimation.POP
"push" -> Screen.ReplaceAnimation.PUSH
else -> throw JSApplicationIllegalArgumentException("Unknown replace animation type $animation")
}
}
@ReactProp(name = "screenOrientation")
override fun setScreenOrientation(
view: Screen,
screenOrientation: String?,
) {
view.setScreenOrientation(screenOrientation)
}
@ReactProp(name = "statusBarAnimation")
override fun setStatusBarAnimation(
view: Screen,
statusBarAnimation: String?,
) {
val animated = statusBarAnimation != null && "none" != statusBarAnimation
view.isStatusBarAnimated = animated
}
@ReactProp(name = "statusBarColor", customType = "Color")
override fun setStatusBarColor(
view: Screen,
statusBarColor: Int?,
) {
view.statusBarColor = statusBarColor
}
@ReactProp(name = "statusBarStyle")
override fun setStatusBarStyle(
view: Screen,
statusBarStyle: String?,
) {
view.statusBarStyle = statusBarStyle
}
@ReactProp(name = "statusBarTranslucent")
override fun setStatusBarTranslucent(
view: Screen,
statusBarTranslucent: Boolean,
) {
view.isStatusBarTranslucent = statusBarTranslucent
}
@ReactProp(name = "statusBarHidden")
override fun setStatusBarHidden(
view: Screen,
statusBarHidden: Boolean,
) {
view.isStatusBarHidden = statusBarHidden
}
@ReactProp(name = "navigationBarColor", customType = "Color")
override fun setNavigationBarColor(
view: Screen,
navigationBarColor: Int?,
) {
view.navigationBarColor = navigationBarColor
}
@ReactProp(name = "navigationBarTranslucent")
override fun setNavigationBarTranslucent(
view: Screen,
navigationBarTranslucent: Boolean,
) {
view.isNavigationBarTranslucent = navigationBarTranslucent
}
@ReactProp(name = "navigationBarHidden")
override fun setNavigationBarHidden(
view: Screen,
navigationBarHidden: Boolean,
) {
view.isNavigationBarHidden = navigationBarHidden
}
@ReactProp(name = "nativeBackButtonDismissalEnabled")
override fun setNativeBackButtonDismissalEnabled(
view: Screen,
nativeBackButtonDismissalEnabled: Boolean,
) {
view.nativeBackButtonDismissalEnabled = nativeBackButtonDismissalEnabled
}
// these props are not available on Android, however we must override their setters
override fun setFullScreenSwipeEnabled(
view: Screen?,
value: Boolean,
) = Unit
override fun setTransitionDuration(
view: Screen?,
value: Int,
) = Unit
override fun setHideKeyboardOnSwipe(
view: Screen?,
value: Boolean,
) = Unit
override fun setCustomAnimationOnSwipe(
view: Screen?,
value: Boolean,
) = Unit
override fun setGestureResponseDistance(
view: Screen?,
value: ReadableMap?,
) = Unit
override fun setHomeIndicatorHidden(
view: Screen?,
value: Boolean,
) = Unit
override fun setPreventNativeDismiss(
view: Screen?,
value: Boolean,
) = Unit
override fun setSwipeDirection(
view: Screen?,
value: String?,
) = Unit
override fun setSheetAllowedDetents(
view: Screen,
value: String?,
) = Unit
override fun setSheetLargestUndimmedDetent(
view: Screen,
value: String?,
) = Unit
override fun setSheetGrabberVisible(
view: Screen?,
value: Boolean,
) = Unit
override fun setSheetCornerRadius(
view: Screen?,
value: Float,
) = Unit
override fun setSheetExpandsWhenScrolledToEdge(
view: Screen?,
value: Boolean,
) = Unit
override fun getExportedCustomDirectEventTypeConstants(): MutableMap<String, Any> =
mutableMapOf(
ScreenDismissedEvent.EVENT_NAME to MapBuilder.of("registrationName", "onDismissed"),
ScreenWillAppearEvent.EVENT_NAME to MapBuilder.of("registrationName", "onWillAppear"),
ScreenAppearEvent.EVENT_NAME to MapBuilder.of("registrationName", "onAppear"),
ScreenWillDisappearEvent.EVENT_NAME to MapBuilder.of("registrationName", "onWillDisappear"),
ScreenDisappearEvent.EVENT_NAME to MapBuilder.of("registrationName", "onDisappear"),
HeaderHeightChangeEvent.EVENT_NAME to MapBuilder.of("registrationName", "onHeaderHeightChange"),
HeaderBackButtonClickedEvent.EVENT_NAME to MapBuilder.of("registrationName", "onHeaderBackButtonClicked"),
ScreenTransitionProgressEvent.EVENT_NAME to MapBuilder.of("registrationName", "onTransitionProgress"),
)
protected override fun getDelegate(): ViewManagerDelegate<Screen> = delegate
companion object {
const val REACT_CLASS = "RNSScreen"
}
}