-
-
Notifications
You must be signed in to change notification settings - Fork 644
Expand file tree
/
Copy pathflags.ts
More file actions
277 lines (265 loc) · 10.7 KB
/
flags.ts
File metadata and controls
277 lines (265 loc) · 10.7 KB
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
const RNS_SYNCHRONOUS_SCREEN_STATE_UPDATES_DEFAULT = false;
const RNS_SYNCHRONOUS_HEADER_CONFIG_STATE_UPDATES_DEFAULT = true;
const RNS_SYNCHRONOUS_HEADER_SUBVIEW_STATE_UPDATES_DEFAULT = false;
const RNS_ANDROID_LEGACY_TOP_INSET_BEHAVIOR_DEFAULT = false;
const RNS_ANDROID_RESET_SCREEN_SHADOW_STATE_ON_ORIENTATION_CHANGE_DEFAULT =
true;
const RNS_IOS_PREVENT_REATTACHMENT_OF_DISMISSED_SCREENS = true;
const RNS_IOS_PREVENT_REATTACHMENT_OF_DISMISSED_MODALS = true;
const RNS_IOS_26_ALLOW_INTERACTIONS_DURING_TRANSITION = true;
const RNS_DEBUG_LOGGING = false;
// TODO: Migrate freeze here
/**
* Exposes information useful for downstream navigation library implementers,
* so they can keep reasonable backward compatibility, if desired.
*
* We don't mean for this object to only grow in number of fields, however at the same time
* we won't be very hasty to reduce it. Expect gradual changes.
*/
export const compatibilityFlags = {
/**
* Because of a bug introduced in https://github.com/software-mansion/react-native-screens/pull/1646
* react-native-screens v3.21 changed how header's backTitle handles whitespace strings in https://github.com/software-mansion/react-native-screens/pull/1726
* To allow for backwards compatibility in @react-navigation/native-stack we need a way to check if this version or newer is used.
* See https://github.com/react-navigation/react-navigation/pull/11423 for more context.
*/
isNewBackTitleImplementation: true,
/**
* With version 4.0.0 the header implementation has been changed. To allow for backward compat
* with native-stack@v6 we want to expose a way to check whether the new implementation
* is in use or not.
*
* See:
* * https://github.com/software-mansion/react-native-screens/pull/2325
* * https://github.com/react-navigation/react-navigation/pull/12125
*/
usesHeaderFlexboxImplementation: true,
/**
* In https://github.com/software-mansion/react-native-screens/pull/3402, we fix values
* reported in `onHeaderHeightChange` event on Android. To allow backward compatibility in
* `@react-navigation/native-stack`, we expose a way to check whether the new implementation
* is in use or not.
*/
usesNewAndroidHeaderHeightImplementation: true,
/**
* Numerous "breaking changes" in the yet-experimental Tabs API have been
* introduced with version 4.25.0 of the library.
*
* This flag marks the shape of the API that's meant for stabilisation, and
* enables downstream to detect these changes.
*
* See:
* * https://github.com/software-mansion/react-native-screens/pull/3888
* * https://github.com/software-mansion/react-native-screens/pull/3776
* * https://github.com/software-mansion/react-native-screens/pull/3781
* * https://github.com/software-mansion/react-native-screens/pull/3756
* * https://github.com/software-mansion/react-native-screens/pull/3808
* * https://github.com/software-mansion/react-native-screens/pull/3785
* * https://github.com/software-mansion/react-native-screens/pull/3789
* * https://github.com/software-mansion/react-native-screens/pull/3794
* * https://github.com/software-mansion/react-native-screens/pull/3863
* * https://github.com/software-mansion/react-native-screens/pull/3875
* * https://github.com/software-mansion/react-native-screens/pull/3895
* * https://github.com/software-mansion/react-native-screens/pull/3918
*/
usesStableTabsApi: true,
} as const;
const _featureFlags = {
experiment: {
synchronousScreenUpdatesEnabled:
RNS_SYNCHRONOUS_SCREEN_STATE_UPDATES_DEFAULT,
synchronousHeaderConfigUpdatesEnabled:
RNS_SYNCHRONOUS_HEADER_CONFIG_STATE_UPDATES_DEFAULT,
synchronousHeaderSubviewUpdatesEnabled:
RNS_SYNCHRONOUS_HEADER_SUBVIEW_STATE_UPDATES_DEFAULT,
androidLegacyTopInsetBehavior:
RNS_ANDROID_LEGACY_TOP_INSET_BEHAVIOR_DEFAULT,
androidResetScreenShadowStateOnOrientationChangeEnabled:
RNS_ANDROID_RESET_SCREEN_SHADOW_STATE_ON_ORIENTATION_CHANGE_DEFAULT,
iosPreventReattachmentOfDismissedScreens:
RNS_IOS_PREVENT_REATTACHMENT_OF_DISMISSED_SCREENS,
iosPreventReattachmentOfDismissedModals:
RNS_IOS_PREVENT_REATTACHMENT_OF_DISMISSED_MODALS,
ios26AllowInteractionsDuringTransition:
RNS_IOS_26_ALLOW_INTERACTIONS_DURING_TRANSITION,
},
stable: {
debugLogging: RNS_DEBUG_LOGGING,
},
};
type EXPERIMENTAL_FF = keyof typeof _featureFlags.experiment;
type STABLE_FF = keyof typeof _featureFlags.stable;
const createExperimentalFeatureFlagAccessor = <T extends EXPERIMENTAL_FF>(
key: T,
defaultValue: (typeof _featureFlags.experiment)[T],
) => {
return {
get() {
return _featureFlags.experiment[key];
},
set(value: (typeof _featureFlags.experiment)[T]) {
if (
value !== _featureFlags.experiment[key] &&
_featureFlags.experiment[key] !== defaultValue
) {
console.error(
`[RNScreens] ${key} feature flag modified for a second time; this might lead to unexpected effects`,
);
}
_featureFlags.experiment[key] = value;
},
};
};
const createStableFeatureFlagAccessor = <T extends STABLE_FF>(
key: T,
defaultValue: (typeof _featureFlags.stable)[T],
) => {
return {
get() {
return _featureFlags.stable[key];
},
set(value: (typeof _featureFlags.stable)[T]) {
if (
value !== _featureFlags.stable[key] &&
_featureFlags.stable[key] !== defaultValue
) {
console.error(
`[RNScreens] ${key} feature flag modified for a second time; this might lead to unexpected effects`,
);
}
_featureFlags.stable[key] = value;
},
};
};
const synchronousScreenUpdatesAccessor = createExperimentalFeatureFlagAccessor(
'synchronousScreenUpdatesEnabled',
RNS_SYNCHRONOUS_SCREEN_STATE_UPDATES_DEFAULT,
);
const synchronousHeaderConfigUpdatesAccessor =
createExperimentalFeatureFlagAccessor(
'synchronousHeaderConfigUpdatesEnabled',
RNS_SYNCHRONOUS_HEADER_CONFIG_STATE_UPDATES_DEFAULT,
);
const synchronousHeaderSubviewUpdatesAccessor =
createExperimentalFeatureFlagAccessor(
'synchronousHeaderSubviewUpdatesEnabled',
RNS_SYNCHRONOUS_HEADER_SUBVIEW_STATE_UPDATES_DEFAULT,
);
const androidLegacyTopInsetBehaviorAccessor =
createExperimentalFeatureFlagAccessor(
'androidLegacyTopInsetBehavior',
RNS_ANDROID_LEGACY_TOP_INSET_BEHAVIOR_DEFAULT,
);
const androidResetScreenShadowStateOnOrientationChangeAccessor =
createExperimentalFeatureFlagAccessor(
'androidResetScreenShadowStateOnOrientationChangeEnabled',
RNS_ANDROID_RESET_SCREEN_SHADOW_STATE_ON_ORIENTATION_CHANGE_DEFAULT,
);
const iosPreventReattachmentOfDismissedScreensAccessor =
createExperimentalFeatureFlagAccessor(
'iosPreventReattachmentOfDismissedScreens',
RNS_IOS_PREVENT_REATTACHMENT_OF_DISMISSED_SCREENS,
);
const iosPreventReattachmentOfDismissedModalsAccessor =
createExperimentalFeatureFlagAccessor(
'iosPreventReattachmentOfDismissedModals',
RNS_IOS_PREVENT_REATTACHMENT_OF_DISMISSED_MODALS,
);
const ios26AllowInteractionsDuringTransitionAccessor =
createExperimentalFeatureFlagAccessor(
'ios26AllowInteractionsDuringTransition',
RNS_IOS_26_ALLOW_INTERACTIONS_DURING_TRANSITION,
);
const rnsDebugLoggingAccessor = createStableFeatureFlagAccessor(
'debugLogging',
RNS_DEBUG_LOGGING,
);
/**
* Exposes configurable global behaviour of the library.
*
* Most of these can be overridden on particular component level, these are global switches.
*/
export const featureFlags = {
/**
* Flags to enable experimental features. These might be removed w/o notice or moved to stable.
*/
experiment: {
get synchronousScreenUpdatesEnabled() {
return synchronousScreenUpdatesAccessor.get();
},
set synchronousScreenUpdatesEnabled(value: boolean) {
synchronousScreenUpdatesAccessor.set(value);
},
get synchronousHeaderConfigUpdatesEnabled() {
return synchronousHeaderConfigUpdatesAccessor.get();
},
set synchronousHeaderConfigUpdatesEnabled(value: boolean) {
synchronousHeaderConfigUpdatesAccessor.set(value);
},
get synchronousHeaderSubviewUpdatesEnabled() {
return synchronousHeaderSubviewUpdatesAccessor.get();
},
set synchronousHeaderSubviewUpdatesEnabled(value: boolean) {
synchronousHeaderSubviewUpdatesAccessor.set(value);
},
get androidLegacyTopInsetBehavior() {
return androidLegacyTopInsetBehaviorAccessor.get();
},
set androidLegacyTopInsetBehavior(value: boolean) {
androidLegacyTopInsetBehaviorAccessor.set(value);
},
get androidResetScreenShadowStateOnOrientationChangeEnabled() {
return androidResetScreenShadowStateOnOrientationChangeAccessor.get();
},
set androidResetScreenShadowStateOnOrientationChangeEnabled(
value: boolean,
) {
androidResetScreenShadowStateOnOrientationChangeAccessor.set(value);
},
/**
* Enables the fix for native / JS state desynchronization in Stack. On by default.
* PR: https://github.com/software-mansion/react-native-screens/pull/3584
*/
get iosPreventReattachmentOfDismissedScreens() {
return iosPreventReattachmentOfDismissedScreensAccessor.get();
},
set iosPreventReattachmentOfDismissedScreens(value: boolean) {
iosPreventReattachmentOfDismissedScreensAccessor.set(value);
},
/**
* Enables the fix for native / JS state desynchronization for Modals. On by default.
* PR: https://github.com/software-mansion/react-native-screens/pull/3760
*/
get iosPreventReattachmentOfDismissedModals() {
return iosPreventReattachmentOfDismissedModalsAccessor.get();
},
set iosPreventReattachmentOfDismissedModals(value: boolean) {
iosPreventReattachmentOfDismissedModalsAccessor.set(value);
},
/**
* Disables the behavior that blocks interactions during Stack Screen transition.
* The application should immediately react to user gestures, dismissing more screens at once, etc.
* Use only with `iosPreventReattachmentOfDismissedScreens = true` to enable the fix
* for native / JS state desynchronization. On by default.
* PR: https://github.com/software-mansion/react-native-screens/pull/3631
*/
get ios26AllowInteractionsDuringTransition() {
return ios26AllowInteractionsDuringTransitionAccessor.get();
},
set ios26AllowInteractionsDuringTransition(value: boolean) {
ios26AllowInteractionsDuringTransitionAccessor.set(value);
},
},
/**
* Section for stable flags, which can be used to configure library behaviour.
*/
stable: {
get debugLogging() {
return rnsDebugLoggingAccessor.get();
},
set debugLogging(value: boolean) {
rnsDebugLoggingAccessor.set(value);
},
},
};
export default featureFlags;