@leonsilicon/react-native-wishlist 0.0.0 → 0.0.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/README.md +11 -3
- package/cpp/ContentContainer/MGContentContainerComponentDescriptor.h +11 -15
- package/cpp/ItemProvider/ComponentsPool.cpp +3 -2
- package/cpp/ItemProvider/ShadowNodeBinding.cpp +3 -2
- package/cpp/ItemProvider/ShadowNodeCopyMachine.cpp +0 -50
- package/cpp/ItemProvider/ShadowNodeCopyMachine.h +2 -3
- package/lib/commonjs/Components/CaseBase.js +17 -0
- package/lib/commonjs/Components/CaseBase.js.map +1 -0
- package/lib/commonjs/Components/Pressable.js +54 -7
- package/lib/commonjs/Components/Pressable.js.map +1 -1
- package/lib/commonjs/Components/Switch.js +10 -10
- package/lib/commonjs/Components/Switch.js.map +1 -1
- package/lib/commonjs/Specs/NativeContentContainer.js +2 -3
- package/lib/commonjs/Specs/NativeContentContainer.js.map +1 -1
- package/lib/commonjs/Specs/NativeTemplateContainer.js +2 -3
- package/lib/commonjs/Specs/NativeTemplateContainer.js.map +1 -1
- package/lib/commonjs/Specs/NativeTemplateInterceptor.js +2 -3
- package/lib/commonjs/Specs/NativeTemplateInterceptor.js.map +1 -1
- package/lib/commonjs/Specs/NativeWishlist.js +3 -5
- package/lib/commonjs/Specs/NativeWishlist.js.map +1 -1
- package/lib/commonjs/TemplateValue.js +6 -0
- package/lib/commonjs/TemplateValue.js.map +1 -1
- package/lib/commonjs/createTemplateComponent.js +2 -2
- package/lib/commonjs/createTemplateComponent.js.map +1 -1
- package/lib/module/Components/CaseBase.js +12 -0
- package/lib/module/Components/CaseBase.js.map +1 -0
- package/lib/module/Components/Pressable.js +56 -9
- package/lib/module/Components/Pressable.js.map +1 -1
- package/lib/module/Components/Switch.js +3 -7
- package/lib/module/Components/Switch.js.map +1 -1
- package/lib/module/Specs/NativeContentContainer.js +1 -1
- package/lib/module/Specs/NativeContentContainer.js.map +1 -1
- package/lib/module/Specs/NativeTemplateContainer.js +1 -1
- package/lib/module/Specs/NativeTemplateContainer.js.map +1 -1
- package/lib/module/Specs/NativeTemplateInterceptor.js +1 -1
- package/lib/module/Specs/NativeTemplateInterceptor.js.map +1 -1
- package/lib/module/Specs/NativeWishlist.js +1 -2
- package/lib/module/Specs/NativeWishlist.js.map +1 -1
- package/lib/module/TemplateValue.js +6 -0
- package/lib/module/TemplateValue.js.map +1 -1
- package/lib/module/createTemplateComponent.js +1 -1
- package/lib/module/createTemplateComponent.js.map +1 -1
- package/lib/typescript/Components/CaseBase.d.ts +3 -0
- package/lib/typescript/Components/CaseBase.d.ts.map +1 -0
- package/lib/typescript/Components/Pressable.d.ts.map +1 -1
- package/lib/typescript/Components/Switch.d.ts +2 -2
- package/lib/typescript/Components/Switch.d.ts.map +1 -1
- package/lib/typescript/Specs/NativeContentContainer.d.ts +2 -2
- package/lib/typescript/Specs/NativeContentContainer.d.ts.map +1 -1
- package/lib/typescript/Specs/NativeTemplateContainer.d.ts +2 -2
- package/lib/typescript/Specs/NativeTemplateContainer.d.ts.map +1 -1
- package/lib/typescript/Specs/NativeTemplateInterceptor.d.ts +2 -2
- package/lib/typescript/Specs/NativeTemplateInterceptor.d.ts.map +1 -1
- package/lib/typescript/Specs/NativeWishlist.d.ts +3 -4
- package/lib/typescript/Specs/NativeWishlist.d.ts.map +1 -1
- package/lib/typescript/TemplateValue.d.ts +5 -0
- package/lib/typescript/TemplateValue.d.ts.map +1 -1
- package/package.json +38 -40
- package/src/Components/CaseBase.tsx +6 -0
- package/src/Components/Pressable.tsx +70 -12
- package/src/Components/Switch.tsx +4 -5
- package/src/Specs/NativeContentContainer.ts +1 -2
- package/src/Specs/NativeTemplateContainer.ts +1 -2
- package/src/Specs/NativeTemplateInterceptor.ts +1 -2
- package/src/Specs/NativeWishlist.ts +7 -6
- package/src/TemplateValue.tsx +5 -0
- package/src/createTemplateComponent.tsx +1 -1
|
@@ -1,17 +1,20 @@
|
|
|
1
1
|
import React, { forwardRef } from 'react';
|
|
2
|
-
import { NativeModules, View, ViewProps } from 'react-native';
|
|
2
|
+
import { DeviceEventEmitter, NativeModules, View, ViewProps } from 'react-native';
|
|
3
3
|
import { createTemplateComponent } from '../createTemplateComponent';
|
|
4
4
|
import { useTemplateCallback } from '../EventHandler';
|
|
5
5
|
import { getUIInflatorRegistry } from '../InflatorRepository';
|
|
6
|
-
import { createRunInJsFn } from '../WishlistJsRuntime';
|
|
6
|
+
import { createRunInWishlistFn, createRunInJsFn } from '../WishlistJsRuntime';
|
|
7
7
|
|
|
8
|
-
//
|
|
8
|
+
// Mirrors `RNGestureHandlerActionType` in react-native-gesture-handler. On the
|
|
9
|
+
// new architecture every state-change action type routes through
|
|
10
|
+
// `sendDeviceEventWithName:@"onGestureHandlerStateChange"` (a global JS device
|
|
11
|
+
// event), so we listen via `DeviceEventEmitter` and dispatch into the wishlist
|
|
12
|
+
// worklet runtime ourselves rather than relying on Fabric event observers.
|
|
9
13
|
const ActionType = {
|
|
10
14
|
REANIMATED_WORKLET: 1,
|
|
11
15
|
NATIVE_ANIMATED_EVENT: 2,
|
|
12
16
|
JS_FUNCTION_OLD_API: 3,
|
|
13
17
|
JS_FUNCTION_NEW_API: 4,
|
|
14
|
-
DIRECT_EVENT: 5,
|
|
15
18
|
} as const;
|
|
16
19
|
|
|
17
20
|
type ActionTypeT = (typeof ActionType)[keyof typeof ActionType];
|
|
@@ -38,12 +41,20 @@ type RNGestureHandlerModuleProps = {
|
|
|
38
41
|
flushOperations: () => void;
|
|
39
42
|
};
|
|
40
43
|
|
|
41
|
-
|
|
44
|
+
// Start above the range RNGH typically issues for handlers created via JS so
|
|
45
|
+
// our auto-generated tags don't collide with user-created gestures. Offset by
|
|
46
|
+
// a per-load random base so a Metro JS reload doesn't reuse the tags from the
|
|
47
|
+
// previous load (RNGH's native registry persists across JS reloads and would
|
|
48
|
+
// throw `HandlerAlreadyRegistered`).
|
|
49
|
+
let _handlerTag = 100000 + Math.floor(Math.random() * 1_000_000);
|
|
42
50
|
|
|
43
51
|
export function getNextHandlerTag(): number {
|
|
44
52
|
return _handlerTag++;
|
|
45
53
|
}
|
|
46
54
|
|
|
55
|
+
const _attachedViewTags = new Set<number>();
|
|
56
|
+
const _handlerTagToViewTag = new Map<number, number>();
|
|
57
|
+
|
|
47
58
|
const RNGestureHandlerModule: RNGestureHandlerModuleProps =
|
|
48
59
|
NativeModules.RNGestureHandlerModule;
|
|
49
60
|
|
|
@@ -56,22 +67,69 @@ export const State = {
|
|
|
56
67
|
END: 5,
|
|
57
68
|
} as const;
|
|
58
69
|
|
|
70
|
+
const dispatchGestureEventToWishlistRuntime = createRunInWishlistFn(
|
|
71
|
+
(viewTag: number, event: any) => {
|
|
72
|
+
'worklet';
|
|
73
|
+
const handleEvent = global.handleEvent;
|
|
74
|
+
if (typeof handleEvent === 'function') {
|
|
75
|
+
handleEvent('onGestureHandlerStateChange', viewTag, event);
|
|
76
|
+
}
|
|
77
|
+
},
|
|
78
|
+
);
|
|
79
|
+
|
|
80
|
+
let _gestureListenerInstalled = false;
|
|
81
|
+
function installGestureListener() {
|
|
82
|
+
if (_gestureListenerInstalled) {
|
|
83
|
+
return;
|
|
84
|
+
}
|
|
85
|
+
_gestureListenerInstalled = true;
|
|
86
|
+
DeviceEventEmitter.addListener(
|
|
87
|
+
'onGestureHandlerStateChange',
|
|
88
|
+
(event: { handlerTag: number; state: number }) => {
|
|
89
|
+
const viewTag = _handlerTagToViewTag.get(event.handlerTag);
|
|
90
|
+
if (viewTag == null) {
|
|
91
|
+
return;
|
|
92
|
+
}
|
|
93
|
+
dispatchGestureEventToWishlistRuntime(viewTag, event);
|
|
94
|
+
},
|
|
95
|
+
);
|
|
96
|
+
}
|
|
97
|
+
|
|
59
98
|
type PressableProps = ViewProps & {
|
|
60
99
|
onPress?: ((item: any, rootItem: any) => void) | null;
|
|
61
100
|
};
|
|
62
101
|
|
|
63
102
|
const attachGestureHandler = createRunInJsFn((tag: number) => {
|
|
64
|
-
|
|
103
|
+
if (_attachedViewTags.has(tag)) {
|
|
104
|
+
return;
|
|
105
|
+
}
|
|
106
|
+
_attachedViewTags.add(tag);
|
|
107
|
+
installGestureListener();
|
|
65
108
|
const handlerTag = getNextHandlerTag();
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
109
|
+
_handlerTagToViewTag.set(handlerTag, tag);
|
|
110
|
+
try {
|
|
111
|
+
RNGestureHandlerModule.createGestureHandler(
|
|
112
|
+
'TapGestureHandler',
|
|
113
|
+
handlerTag,
|
|
114
|
+
{},
|
|
115
|
+
);
|
|
116
|
+
} catch (e) {
|
|
117
|
+
// RNGH keeps its handler registry alive across Metro JS reloads. If a
|
|
118
|
+
// handler with this tag already exists from a prior load, drop it and
|
|
119
|
+
// retry — losing the stale handler is fine since its view is gone too.
|
|
120
|
+
try {
|
|
121
|
+
RNGestureHandlerModule.dropGestureHandler(handlerTag);
|
|
122
|
+
} catch {}
|
|
123
|
+
RNGestureHandlerModule.createGestureHandler(
|
|
124
|
+
'TapGestureHandler',
|
|
125
|
+
handlerTag,
|
|
126
|
+
{},
|
|
127
|
+
);
|
|
128
|
+
}
|
|
71
129
|
RNGestureHandlerModule.attachGestureHandler(
|
|
72
130
|
handlerTag,
|
|
73
131
|
tag,
|
|
74
|
-
ActionType.
|
|
132
|
+
ActionType.JS_FUNCTION_OLD_API,
|
|
75
133
|
);
|
|
76
134
|
RNGestureHandlerModule.flushOperations();
|
|
77
135
|
});
|
|
@@ -1,7 +1,10 @@
|
|
|
1
|
-
import React
|
|
1
|
+
import React from 'react';
|
|
2
2
|
import { View, ViewStyle } from 'react-native';
|
|
3
3
|
import { createTemplateComponent } from '../createTemplateComponent';
|
|
4
4
|
import type { TemplateValue } from '../TemplateValue';
|
|
5
|
+
import { CaseBase } from './CaseBase';
|
|
6
|
+
|
|
7
|
+
export { CaseBase };
|
|
5
8
|
|
|
6
9
|
const SwitchTemplateComponent = createTemplateComponent(View);
|
|
7
10
|
|
|
@@ -23,10 +26,6 @@ export function Switch(props: SwitchProps) {
|
|
|
23
26
|
return <SwitchTemplateComponent {...props} children={children} />;
|
|
24
27
|
}
|
|
25
28
|
|
|
26
|
-
export const CaseBase = forwardRef<any, any>((props, ref) => {
|
|
27
|
-
return <View {...props} ref={ref} />;
|
|
28
|
-
});
|
|
29
|
-
|
|
30
29
|
const CaseTemplateComponent = createTemplateComponent(CaseBase, {
|
|
31
30
|
addProps: (item, props) => {
|
|
32
31
|
'worklet';
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import type
|
|
2
|
-
import codegenNativeComponent from 'react-native/Libraries/Utilities/codegenNativeComponent';
|
|
1
|
+
import { codegenNativeComponent, type ViewProps } from 'react-native';
|
|
3
2
|
|
|
4
3
|
export interface NativeContentContainerProps extends ViewProps {}
|
|
5
4
|
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import type
|
|
2
|
-
import codegenNativeComponent from 'react-native/Libraries/Utilities/codegenNativeComponent';
|
|
1
|
+
import { codegenNativeComponent, type ViewProps } from 'react-native';
|
|
3
2
|
|
|
4
3
|
export interface NativeTemplateContainerProps extends ViewProps {
|
|
5
4
|
inflatorId: string;
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import type
|
|
2
|
-
import codegenNativeComponent from 'react-native/Libraries/Utilities/codegenNativeComponent';
|
|
1
|
+
import { codegenNativeComponent, type ViewProps } from 'react-native';
|
|
3
2
|
|
|
4
3
|
export interface NativeTemplateInterceptorProps extends ViewProps {}
|
|
5
4
|
|
|
@@ -1,14 +1,15 @@
|
|
|
1
1
|
import type * as React from 'react';
|
|
2
|
-
import
|
|
2
|
+
import {
|
|
3
|
+
codegenNativeCommands,
|
|
4
|
+
codegenNativeComponent,
|
|
5
|
+
type HostComponent,
|
|
6
|
+
type ViewProps,
|
|
7
|
+
} from 'react-native';
|
|
3
8
|
import type {
|
|
4
9
|
DirectEventHandler,
|
|
5
10
|
Double,
|
|
6
11
|
Int32,
|
|
7
12
|
} from 'react-native/Libraries/Types/CodegenTypes';
|
|
8
|
-
import codegenNativeCommands from 'react-native/Libraries/Utilities/codegenNativeCommands';
|
|
9
|
-
import codegenNativeComponent, {
|
|
10
|
-
NativeComponentType,
|
|
11
|
-
} from 'react-native/Libraries/Utilities/codegenNativeComponent';
|
|
12
13
|
|
|
13
14
|
export type EventInFile = Readonly<{
|
|
14
15
|
value: Double;
|
|
@@ -21,7 +22,7 @@ export interface WishlistProps extends ViewProps {
|
|
|
21
22
|
onEndReached?: DirectEventHandler<Readonly<{}>>;
|
|
22
23
|
}
|
|
23
24
|
|
|
24
|
-
type NativeType =
|
|
25
|
+
type NativeType = HostComponent<WishlistProps>;
|
|
25
26
|
|
|
26
27
|
export type ScrollToItem = (
|
|
27
28
|
viewRef: React.ElementRef<NativeType>,
|
package/src/TemplateValue.tsx
CHANGED
|
@@ -86,6 +86,11 @@ export function isTemplateValue(
|
|
|
86
86
|
);
|
|
87
87
|
}
|
|
88
88
|
|
|
89
|
+
/**
|
|
90
|
+
* The `mapper` runs on the UI worklet runtime. Mark it (and any nested function
|
|
91
|
+
* literals it passes to helpers like `Array#reduce`) with a leading
|
|
92
|
+
* `'worklet';` statement so `react-native-worklets-core` can compile them.
|
|
93
|
+
*/
|
|
89
94
|
export function useTemplateValue<ItemT, ValueT>(
|
|
90
95
|
mapper: TemplateValueMapper<ItemT, ValueT>,
|
|
91
96
|
): TemplateValue<ValueT> {
|
|
@@ -5,7 +5,7 @@ import { ForEachBase } from './Components/ForEachBase';
|
|
|
5
5
|
import InflatorRepository, {
|
|
6
6
|
getUIInflatorRegistry,
|
|
7
7
|
} from './InflatorRepository';
|
|
8
|
-
import { CaseBase } from './Components/
|
|
8
|
+
import { CaseBase } from './Components/CaseBase';
|
|
9
9
|
import { useTemplateContext } from './TemplateContext';
|
|
10
10
|
import {
|
|
11
11
|
createTemplateValue,
|