stream-chat-react-native-core 9.7.0 → 9.7.1-beta.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/commonjs/components/Message/utils/measureInWindow.js +51 -8
- package/lib/commonjs/components/Message/utils/measureInWindow.js.map +1 -1
- package/lib/commonjs/components/UIComponents/PortalWhileClosingView.js +6 -13
- package/lib/commonjs/components/UIComponents/PortalWhileClosingView.js.map +1 -1
- package/lib/commonjs/mock-builders/DB/mock.js +2 -0
- package/lib/commonjs/mock-builders/DB/mock.js.map +1 -1
- package/lib/commonjs/utils/isRNVersionGreaterThanOrEqualTo.js +22 -0
- package/lib/commonjs/utils/isRNVersionGreaterThanOrEqualTo.js.map +1 -0
- package/lib/commonjs/utils/react-native-constants.js +7 -0
- package/lib/commonjs/utils/react-native-constants.js.map +1 -0
- package/lib/commonjs/version.json +1 -1
- package/lib/module/components/Message/utils/measureInWindow.js +51 -8
- package/lib/module/components/Message/utils/measureInWindow.js.map +1 -1
- package/lib/module/components/UIComponents/PortalWhileClosingView.js +6 -13
- package/lib/module/components/UIComponents/PortalWhileClosingView.js.map +1 -1
- package/lib/module/mock-builders/DB/mock.js +2 -0
- package/lib/module/mock-builders/DB/mock.js.map +1 -1
- package/lib/module/utils/isRNVersionGreaterThanOrEqualTo.js +22 -0
- package/lib/module/utils/isRNVersionGreaterThanOrEqualTo.js.map +1 -0
- package/lib/module/utils/react-native-constants.js +7 -0
- package/lib/module/utils/react-native-constants.js.map +1 -0
- package/lib/module/version.json +1 -1
- package/lib/typescript/components/Message/utils/measureInWindow.d.ts +12 -2
- package/lib/typescript/components/Message/utils/measureInWindow.d.ts.map +1 -1
- package/lib/typescript/components/UIComponents/PortalWhileClosingView.d.ts.map +1 -1
- package/lib/typescript/utils/isRNVersionGreaterThanOrEqualTo.d.ts +9 -0
- package/lib/typescript/utils/isRNVersionGreaterThanOrEqualTo.d.ts.map +1 -0
- package/lib/typescript/utils/react-native-constants.d.ts +8 -0
- package/lib/typescript/utils/react-native-constants.d.ts.map +1 -0
- package/package.json +10 -10
- package/src/__tests__/offline-support/offline-feature.tsx +43 -34
- package/src/components/Message/utils/__tests__/measureInWindow.test.ts +217 -0
- package/src/components/Message/utils/measureInWindow.ts +69 -6
- package/src/components/MessageInput/__tests__/__snapshots__/AttachButton.test.tsx.snap +15 -0
- package/src/components/MessageInput/__tests__/__snapshots__/SendButton.test.tsx.snap +10 -0
- package/src/components/MessageList/__tests__/__snapshots__/ScrollToBottomButton.test.tsx.snap +1 -0
- package/src/components/Thread/__tests__/__snapshots__/Thread.test.tsx.snap +6 -0
- package/src/components/UIComponents/PortalWhileClosingView.tsx +9 -14
- package/src/mock-builders/DB/mock.ts +2 -0
- package/src/utils/__tests__/isRNVersionGreaterThanOrEqualTo.test.ts +60 -0
- package/src/utils/isRNVersionGreaterThanOrEqualTo.ts +27 -0
- package/src/utils/react-native-constants.ts +10 -0
- package/src/version.json +1 -1
|
@@ -47,6 +47,7 @@ exports[`AttachButton should call handleAttachButtonPress when the button is cli
|
|
|
47
47
|
onGestureHandlerReanimatedEvent={[Function]}
|
|
48
48
|
onGestureHandlerStateChange={[Function]}
|
|
49
49
|
onGestureHandlerTouchEvent={[Function]}
|
|
50
|
+
onStartShouldSetResponder={[Function]}
|
|
50
51
|
pointerEvents="box-none"
|
|
51
52
|
style={
|
|
52
53
|
{
|
|
@@ -221,6 +222,7 @@ exports[`AttachButton should call handleAttachButtonPress when the button is cli
|
|
|
221
222
|
onGestureHandlerReanimatedEvent={[Function]}
|
|
222
223
|
onGestureHandlerStateChange={[Function]}
|
|
223
224
|
onGestureHandlerTouchEvent={[Function]}
|
|
225
|
+
onStartShouldSetResponder={[Function]}
|
|
224
226
|
pointerEvents="box-none"
|
|
225
227
|
style={
|
|
226
228
|
{
|
|
@@ -368,6 +370,7 @@ exports[`AttachButton should call handleAttachButtonPress when the button is cli
|
|
|
368
370
|
onGestureHandlerReanimatedEvent={[Function]}
|
|
369
371
|
onGestureHandlerStateChange={[Function]}
|
|
370
372
|
onGestureHandlerTouchEvent={[Function]}
|
|
373
|
+
onStartShouldSetResponder={[Function]}
|
|
371
374
|
pointerEvents="box-none"
|
|
372
375
|
style={
|
|
373
376
|
{
|
|
@@ -544,6 +547,7 @@ exports[`AttachButton should call handleAttachButtonPress when the button is cli
|
|
|
544
547
|
onGestureHandlerReanimatedEvent={[Function]}
|
|
545
548
|
onGestureHandlerStateChange={[Function]}
|
|
546
549
|
onGestureHandlerTouchEvent={[Function]}
|
|
550
|
+
onStartShouldSetResponder={[Function]}
|
|
547
551
|
pointerEvents="box-none"
|
|
548
552
|
style={
|
|
549
553
|
{
|
|
@@ -687,6 +691,7 @@ exports[`AttachButton should call handleAttachButtonPress when the button is cli
|
|
|
687
691
|
onGestureHandlerReanimatedEvent={[Function]}
|
|
688
692
|
onGestureHandlerStateChange={[Function]}
|
|
689
693
|
onGestureHandlerTouchEvent={[Function]}
|
|
694
|
+
onStartShouldSetResponder={[Function]}
|
|
690
695
|
pointerEvents="box-none"
|
|
691
696
|
style={
|
|
692
697
|
{
|
|
@@ -963,6 +968,7 @@ exports[`AttachButton should render a enabled AttachButton 1`] = `
|
|
|
963
968
|
onGestureHandlerReanimatedEvent={[Function]}
|
|
964
969
|
onGestureHandlerStateChange={[Function]}
|
|
965
970
|
onGestureHandlerTouchEvent={[Function]}
|
|
971
|
+
onStartShouldSetResponder={[Function]}
|
|
966
972
|
pointerEvents="box-none"
|
|
967
973
|
style={
|
|
968
974
|
{
|
|
@@ -1137,6 +1143,7 @@ exports[`AttachButton should render a enabled AttachButton 1`] = `
|
|
|
1137
1143
|
onGestureHandlerReanimatedEvent={[Function]}
|
|
1138
1144
|
onGestureHandlerStateChange={[Function]}
|
|
1139
1145
|
onGestureHandlerTouchEvent={[Function]}
|
|
1146
|
+
onStartShouldSetResponder={[Function]}
|
|
1140
1147
|
pointerEvents="box-none"
|
|
1141
1148
|
style={
|
|
1142
1149
|
{
|
|
@@ -1284,6 +1291,7 @@ exports[`AttachButton should render a enabled AttachButton 1`] = `
|
|
|
1284
1291
|
onGestureHandlerReanimatedEvent={[Function]}
|
|
1285
1292
|
onGestureHandlerStateChange={[Function]}
|
|
1286
1293
|
onGestureHandlerTouchEvent={[Function]}
|
|
1294
|
+
onStartShouldSetResponder={[Function]}
|
|
1287
1295
|
pointerEvents="box-none"
|
|
1288
1296
|
style={
|
|
1289
1297
|
{
|
|
@@ -1460,6 +1468,7 @@ exports[`AttachButton should render a enabled AttachButton 1`] = `
|
|
|
1460
1468
|
onGestureHandlerReanimatedEvent={[Function]}
|
|
1461
1469
|
onGestureHandlerStateChange={[Function]}
|
|
1462
1470
|
onGestureHandlerTouchEvent={[Function]}
|
|
1471
|
+
onStartShouldSetResponder={[Function]}
|
|
1463
1472
|
pointerEvents="box-none"
|
|
1464
1473
|
style={
|
|
1465
1474
|
{
|
|
@@ -1603,6 +1612,7 @@ exports[`AttachButton should render a enabled AttachButton 1`] = `
|
|
|
1603
1612
|
onGestureHandlerReanimatedEvent={[Function]}
|
|
1604
1613
|
onGestureHandlerStateChange={[Function]}
|
|
1605
1614
|
onGestureHandlerTouchEvent={[Function]}
|
|
1615
|
+
onStartShouldSetResponder={[Function]}
|
|
1606
1616
|
pointerEvents="box-none"
|
|
1607
1617
|
style={
|
|
1608
1618
|
{
|
|
@@ -1879,6 +1889,7 @@ exports[`AttachButton should render an disabled AttachButton 1`] = `
|
|
|
1879
1889
|
onGestureHandlerReanimatedEvent={[Function]}
|
|
1880
1890
|
onGestureHandlerStateChange={[Function]}
|
|
1881
1891
|
onGestureHandlerTouchEvent={[Function]}
|
|
1892
|
+
onStartShouldSetResponder={[Function]}
|
|
1882
1893
|
pointerEvents="box-none"
|
|
1883
1894
|
style={
|
|
1884
1895
|
{
|
|
@@ -2053,6 +2064,7 @@ exports[`AttachButton should render an disabled AttachButton 1`] = `
|
|
|
2053
2064
|
onGestureHandlerReanimatedEvent={[Function]}
|
|
2054
2065
|
onGestureHandlerStateChange={[Function]}
|
|
2055
2066
|
onGestureHandlerTouchEvent={[Function]}
|
|
2067
|
+
onStartShouldSetResponder={[Function]}
|
|
2056
2068
|
pointerEvents="box-none"
|
|
2057
2069
|
style={
|
|
2058
2070
|
{
|
|
@@ -2200,6 +2212,7 @@ exports[`AttachButton should render an disabled AttachButton 1`] = `
|
|
|
2200
2212
|
onGestureHandlerReanimatedEvent={[Function]}
|
|
2201
2213
|
onGestureHandlerStateChange={[Function]}
|
|
2202
2214
|
onGestureHandlerTouchEvent={[Function]}
|
|
2215
|
+
onStartShouldSetResponder={[Function]}
|
|
2203
2216
|
pointerEvents="box-none"
|
|
2204
2217
|
style={
|
|
2205
2218
|
{
|
|
@@ -2376,6 +2389,7 @@ exports[`AttachButton should render an disabled AttachButton 1`] = `
|
|
|
2376
2389
|
onGestureHandlerReanimatedEvent={[Function]}
|
|
2377
2390
|
onGestureHandlerStateChange={[Function]}
|
|
2378
2391
|
onGestureHandlerTouchEvent={[Function]}
|
|
2392
|
+
onStartShouldSetResponder={[Function]}
|
|
2379
2393
|
pointerEvents="box-none"
|
|
2380
2394
|
style={
|
|
2381
2395
|
{
|
|
@@ -2519,6 +2533,7 @@ exports[`AttachButton should render an disabled AttachButton 1`] = `
|
|
|
2519
2533
|
onGestureHandlerReanimatedEvent={[Function]}
|
|
2520
2534
|
onGestureHandlerStateChange={[Function]}
|
|
2521
2535
|
onGestureHandlerTouchEvent={[Function]}
|
|
2536
|
+
onStartShouldSetResponder={[Function]}
|
|
2522
2537
|
pointerEvents="box-none"
|
|
2523
2538
|
style={
|
|
2524
2539
|
{
|
|
@@ -47,6 +47,7 @@ exports[`SendButton should render a SendButton 1`] = `
|
|
|
47
47
|
onGestureHandlerReanimatedEvent={[Function]}
|
|
48
48
|
onGestureHandlerStateChange={[Function]}
|
|
49
49
|
onGestureHandlerTouchEvent={[Function]}
|
|
50
|
+
onStartShouldSetResponder={[Function]}
|
|
50
51
|
pointerEvents="box-none"
|
|
51
52
|
style={
|
|
52
53
|
{
|
|
@@ -219,6 +220,7 @@ exports[`SendButton should render a SendButton 1`] = `
|
|
|
219
220
|
onGestureHandlerReanimatedEvent={[Function]}
|
|
220
221
|
onGestureHandlerStateChange={[Function]}
|
|
221
222
|
onGestureHandlerTouchEvent={[Function]}
|
|
223
|
+
onStartShouldSetResponder={[Function]}
|
|
222
224
|
pointerEvents="box-none"
|
|
223
225
|
style={
|
|
224
226
|
{
|
|
@@ -366,6 +368,7 @@ exports[`SendButton should render a SendButton 1`] = `
|
|
|
366
368
|
onGestureHandlerReanimatedEvent={[Function]}
|
|
367
369
|
onGestureHandlerStateChange={[Function]}
|
|
368
370
|
onGestureHandlerTouchEvent={[Function]}
|
|
371
|
+
onStartShouldSetResponder={[Function]}
|
|
369
372
|
pointerEvents="box-none"
|
|
370
373
|
style={
|
|
371
374
|
{
|
|
@@ -542,6 +545,7 @@ exports[`SendButton should render a SendButton 1`] = `
|
|
|
542
545
|
onGestureHandlerReanimatedEvent={[Function]}
|
|
543
546
|
onGestureHandlerStateChange={[Function]}
|
|
544
547
|
onGestureHandlerTouchEvent={[Function]}
|
|
548
|
+
onStartShouldSetResponder={[Function]}
|
|
545
549
|
pointerEvents="box-none"
|
|
546
550
|
style={
|
|
547
551
|
{
|
|
@@ -685,6 +689,7 @@ exports[`SendButton should render a SendButton 1`] = `
|
|
|
685
689
|
onGestureHandlerReanimatedEvent={[Function]}
|
|
686
690
|
onGestureHandlerStateChange={[Function]}
|
|
687
691
|
onGestureHandlerTouchEvent={[Function]}
|
|
692
|
+
onStartShouldSetResponder={[Function]}
|
|
688
693
|
pointerEvents="box-none"
|
|
689
694
|
style={
|
|
690
695
|
{
|
|
@@ -961,6 +966,7 @@ exports[`SendButton should render a disabled SendButton 1`] = `
|
|
|
961
966
|
onGestureHandlerReanimatedEvent={[Function]}
|
|
962
967
|
onGestureHandlerStateChange={[Function]}
|
|
963
968
|
onGestureHandlerTouchEvent={[Function]}
|
|
969
|
+
onStartShouldSetResponder={[Function]}
|
|
964
970
|
pointerEvents="box-none"
|
|
965
971
|
style={
|
|
966
972
|
{
|
|
@@ -1133,6 +1139,7 @@ exports[`SendButton should render a disabled SendButton 1`] = `
|
|
|
1133
1139
|
onGestureHandlerReanimatedEvent={[Function]}
|
|
1134
1140
|
onGestureHandlerStateChange={[Function]}
|
|
1135
1141
|
onGestureHandlerTouchEvent={[Function]}
|
|
1142
|
+
onStartShouldSetResponder={[Function]}
|
|
1136
1143
|
pointerEvents="box-none"
|
|
1137
1144
|
style={
|
|
1138
1145
|
{
|
|
@@ -1280,6 +1287,7 @@ exports[`SendButton should render a disabled SendButton 1`] = `
|
|
|
1280
1287
|
onGestureHandlerReanimatedEvent={[Function]}
|
|
1281
1288
|
onGestureHandlerStateChange={[Function]}
|
|
1282
1289
|
onGestureHandlerTouchEvent={[Function]}
|
|
1290
|
+
onStartShouldSetResponder={[Function]}
|
|
1283
1291
|
pointerEvents="box-none"
|
|
1284
1292
|
style={
|
|
1285
1293
|
{
|
|
@@ -1456,6 +1464,7 @@ exports[`SendButton should render a disabled SendButton 1`] = `
|
|
|
1456
1464
|
onGestureHandlerReanimatedEvent={[Function]}
|
|
1457
1465
|
onGestureHandlerStateChange={[Function]}
|
|
1458
1466
|
onGestureHandlerTouchEvent={[Function]}
|
|
1467
|
+
onStartShouldSetResponder={[Function]}
|
|
1459
1468
|
pointerEvents="box-none"
|
|
1460
1469
|
style={
|
|
1461
1470
|
{
|
|
@@ -1599,6 +1608,7 @@ exports[`SendButton should render a disabled SendButton 1`] = `
|
|
|
1599
1608
|
onGestureHandlerReanimatedEvent={[Function]}
|
|
1600
1609
|
onGestureHandlerStateChange={[Function]}
|
|
1601
1610
|
onGestureHandlerTouchEvent={[Function]}
|
|
1611
|
+
onStartShouldSetResponder={[Function]}
|
|
1602
1612
|
pointerEvents="box-none"
|
|
1603
1613
|
style={
|
|
1604
1614
|
{
|
package/src/components/MessageList/__tests__/__snapshots__/ScrollToBottomButton.test.tsx.snap
CHANGED
|
@@ -61,6 +61,7 @@ exports[`ScrollToBottomButton should render the message notification and match s
|
|
|
61
61
|
onGestureHandlerReanimatedEvent={[Function]}
|
|
62
62
|
onGestureHandlerStateChange={[Function]}
|
|
63
63
|
onGestureHandlerTouchEvent={[Function]}
|
|
64
|
+
onStartShouldSetResponder={[Function]}
|
|
64
65
|
pointerEvents="box-none"
|
|
65
66
|
style={
|
|
66
67
|
{
|
|
@@ -1846,6 +1846,7 @@ exports[`Thread should match thread snapshot 1`] = `
|
|
|
1846
1846
|
onGestureHandlerReanimatedEvent={[Function]}
|
|
1847
1847
|
onGestureHandlerStateChange={[Function]}
|
|
1848
1848
|
onGestureHandlerTouchEvent={[Function]}
|
|
1849
|
+
onStartShouldSetResponder={[Function]}
|
|
1849
1850
|
pointerEvents="box-none"
|
|
1850
1851
|
style={
|
|
1851
1852
|
{
|
|
@@ -2224,6 +2225,7 @@ exports[`Thread should match thread snapshot 1`] = `
|
|
|
2224
2225
|
onGestureHandlerReanimatedEvent={[Function]}
|
|
2225
2226
|
onGestureHandlerStateChange={[Function]}
|
|
2226
2227
|
onGestureHandlerTouchEvent={[Function]}
|
|
2228
|
+
onStartShouldSetResponder={[Function]}
|
|
2227
2229
|
pointerEvents="box-none"
|
|
2228
2230
|
style={
|
|
2229
2231
|
{
|
|
@@ -2406,6 +2408,7 @@ exports[`Thread should match thread snapshot 1`] = `
|
|
|
2406
2408
|
onGestureHandlerReanimatedEvent={[Function]}
|
|
2407
2409
|
onGestureHandlerStateChange={[Function]}
|
|
2408
2410
|
onGestureHandlerTouchEvent={[Function]}
|
|
2411
|
+
onStartShouldSetResponder={[Function]}
|
|
2409
2412
|
pointerEvents="box-none"
|
|
2410
2413
|
style={
|
|
2411
2414
|
{
|
|
@@ -2553,6 +2556,7 @@ exports[`Thread should match thread snapshot 1`] = `
|
|
|
2553
2556
|
onGestureHandlerReanimatedEvent={[Function]}
|
|
2554
2557
|
onGestureHandlerStateChange={[Function]}
|
|
2555
2558
|
onGestureHandlerTouchEvent={[Function]}
|
|
2559
|
+
onStartShouldSetResponder={[Function]}
|
|
2556
2560
|
pointerEvents="box-none"
|
|
2557
2561
|
style={
|
|
2558
2562
|
{
|
|
@@ -2729,6 +2733,7 @@ exports[`Thread should match thread snapshot 1`] = `
|
|
|
2729
2733
|
onGestureHandlerReanimatedEvent={[Function]}
|
|
2730
2734
|
onGestureHandlerStateChange={[Function]}
|
|
2731
2735
|
onGestureHandlerTouchEvent={[Function]}
|
|
2736
|
+
onStartShouldSetResponder={[Function]}
|
|
2732
2737
|
pointerEvents="box-none"
|
|
2733
2738
|
style={
|
|
2734
2739
|
{
|
|
@@ -2872,6 +2877,7 @@ exports[`Thread should match thread snapshot 1`] = `
|
|
|
2872
2877
|
onGestureHandlerReanimatedEvent={[Function]}
|
|
2873
2878
|
onGestureHandlerStateChange={[Function]}
|
|
2874
2879
|
onGestureHandlerTouchEvent={[Function]}
|
|
2880
|
+
onStartShouldSetResponder={[Function]}
|
|
2875
2881
|
pointerEvents="box-none"
|
|
2876
2882
|
style={
|
|
2877
2883
|
{
|
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import React, { ReactNode, useEffect, useMemo, useRef } from 'react';
|
|
2
|
-
import {
|
|
2
|
+
import { View } from 'react-native';
|
|
3
3
|
|
|
4
4
|
import Animated, { useAnimatedStyle, useSharedValue } from 'react-native-reanimated';
|
|
5
5
|
import { useSafeAreaInsets } from 'react-native-safe-area-context';
|
|
6
6
|
import { Portal } from 'react-native-teleport';
|
|
7
7
|
|
|
8
|
+
import { measureInWindow } from '../../components/Message/utils/measureInWindow';
|
|
8
9
|
import { useStableCallback } from '../../hooks';
|
|
9
10
|
import {
|
|
10
11
|
clearClosingPortalLayout,
|
|
@@ -124,20 +125,14 @@ const useSyncingApi = (portalHostName: string, registrationId: string) => {
|
|
|
124
125
|
return;
|
|
125
126
|
}
|
|
126
127
|
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
setClosingPortalLayout(portalHostName, registrationId, {
|
|
136
|
-
...absolute,
|
|
137
|
-
h: height,
|
|
138
|
-
w: width,
|
|
128
|
+
measureInWindow(containerRef, insets)
|
|
129
|
+
.then((rect) => {
|
|
130
|
+
placeholderLayout.value = { h: rect.h, w: rect.w };
|
|
131
|
+
setClosingPortalLayout(portalHostName, registrationId, rect);
|
|
132
|
+
})
|
|
133
|
+
.catch(() => {
|
|
134
|
+
// the container isn't measurable yet; the next layout/effect pass will retry
|
|
139
135
|
});
|
|
140
|
-
});
|
|
141
136
|
});
|
|
142
137
|
|
|
143
138
|
useEffect(() => {
|
|
@@ -8,6 +8,8 @@ const testDbName = `foobar-${process.env.JEST_WORKER_ID ?? '0'}.db`;
|
|
|
8
8
|
export const sqliteMock = {
|
|
9
9
|
open: () => {
|
|
10
10
|
db = new Sqlite3(testDbName);
|
|
11
|
+
db.pragma('journal_mode = MEMORY');
|
|
12
|
+
db.pragma('synchronous = OFF');
|
|
11
13
|
return {
|
|
12
14
|
close: () => {
|
|
13
15
|
db.close();
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { Platform } from 'react-native';
|
|
2
|
+
|
|
3
|
+
import { isRNVersionGreaterThanOrEqualTo } from '../isRNVersionGreaterThanOrEqualTo';
|
|
4
|
+
|
|
5
|
+
const setRNVersion = (version?: { major: number; minor: number; patch: number }) => {
|
|
6
|
+
Object.defineProperty(Platform, 'constants', {
|
|
7
|
+
configurable: true,
|
|
8
|
+
get: () => (version ? { reactNativeVersion: version } : {}),
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
describe('isRNVersionGreaterThanOrEqualTo', () => {
|
|
13
|
+
const originalConstants = Platform.constants;
|
|
14
|
+
|
|
15
|
+
afterEach(() => {
|
|
16
|
+
Object.defineProperty(Platform, 'constants', {
|
|
17
|
+
configurable: true,
|
|
18
|
+
get: () => originalConstants,
|
|
19
|
+
});
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
it('compares the major version first', () => {
|
|
23
|
+
setRNVersion({ major: 1, minor: 0, patch: 0 });
|
|
24
|
+
expect(isRNVersionGreaterThanOrEqualTo('0.99.99')).toBe(true);
|
|
25
|
+
|
|
26
|
+
setRNVersion({ major: 0, minor: 99, patch: 99 });
|
|
27
|
+
expect(isRNVersionGreaterThanOrEqualTo('1.0.0')).toBe(false);
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
it('compares the minor version when majors match', () => {
|
|
31
|
+
setRNVersion({ major: 0, minor: 86, patch: 0 });
|
|
32
|
+
expect(isRNVersionGreaterThanOrEqualTo('0.85.9')).toBe(true);
|
|
33
|
+
expect(isRNVersionGreaterThanOrEqualTo('0.87.0')).toBe(false);
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
it('takes the patch version into account when major and minor match', () => {
|
|
37
|
+
setRNVersion({ major: 0, minor: 86, patch: 2 });
|
|
38
|
+
expect(isRNVersionGreaterThanOrEqualTo('0.86.1')).toBe(true);
|
|
39
|
+
expect(isRNVersionGreaterThanOrEqualTo('0.86.2')).toBe(true);
|
|
40
|
+
expect(isRNVersionGreaterThanOrEqualTo('0.86.3')).toBe(false);
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
it('treats an exactly-equal version as satisfied', () => {
|
|
44
|
+
setRNVersion({ major: 0, minor: 86, patch: 1 });
|
|
45
|
+
expect(isRNVersionGreaterThanOrEqualTo('0.86.1')).toBe(true);
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
it('defaults omitted target parts to 0 (e.g. "0.86" means "0.86.0")', () => {
|
|
49
|
+
setRNVersion({ major: 0, minor: 86, patch: 0 });
|
|
50
|
+
expect(isRNVersionGreaterThanOrEqualTo('0.86')).toBe(true);
|
|
51
|
+
|
|
52
|
+
setRNVersion({ major: 0, minor: 86, patch: 1 });
|
|
53
|
+
expect(isRNVersionGreaterThanOrEqualTo('0.86')).toBe(true);
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
it('returns false when the RN version constant is unavailable', () => {
|
|
57
|
+
setRNVersion(undefined);
|
|
58
|
+
expect(isRNVersionGreaterThanOrEqualTo('0.86.0')).toBe(false);
|
|
59
|
+
});
|
|
60
|
+
});
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { Platform } from 'react-native';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Returns `true` when the running React Native version is greater than or equal to `version`
|
|
5
|
+
* (a `'major.minor.patch'` string, e.g. `'0.86.0'`), comparing major, then minor, then patch.
|
|
6
|
+
*
|
|
7
|
+
* Falls back to `false` when the version is unavailable (e.g. react-native-web) — callers should
|
|
8
|
+
* treat that as "assume an older React Native".
|
|
9
|
+
*/
|
|
10
|
+
export const isRNVersionGreaterThanOrEqualTo = (version: string): boolean => {
|
|
11
|
+
const runtime = Platform.constants?.reactNativeVersion;
|
|
12
|
+
if (!runtime) {
|
|
13
|
+
return false;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
const current = [runtime.major, runtime.minor, runtime.patch ?? 0];
|
|
17
|
+
const target = version.split('.').map((part) => parseInt(part, 10) || 0);
|
|
18
|
+
|
|
19
|
+
for (let i = 0; i < current.length; i++) {
|
|
20
|
+
const wanted = target[i] ?? 0;
|
|
21
|
+
if (current[i] !== wanted) {
|
|
22
|
+
return current[i] > wanted;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
return true;
|
|
27
|
+
};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { isRNVersionGreaterThanOrEqualTo } from './isRNVersionGreaterThanOrEqualTo';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* React Native capability flags, resolved once at module load - the RN version is fixed for the
|
|
5
|
+
* lifetime of the app. Keeping version gates as named flags here makes them easy to mock in tests
|
|
6
|
+
* and easy to retire later: when the SDK's minimum supported React Native reaches a baseline, grep
|
|
7
|
+
* for the flag to find every gated code path and delete both the flag and the branches it guarded.
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
export const isRN86OrGreater = isRNVersionGreaterThanOrEqualTo('0.86.0');
|
package/src/version.json
CHANGED