react-native-yoga-jsi 0.1.2 → 0.2.1
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 +29 -17
- package/cpp/macros.h +2 -2
- package/cpp/nodeProperties.h +10 -8
- package/lib/commonjs/derived/styleHandler.js +22 -0
- package/lib/commonjs/derived/styleHandler.js.map +1 -1
- package/lib/commonjs/derived/useStyle.js +0 -5
- package/lib/commonjs/derived/useStyle.js.map +1 -1
- package/lib/commonjs/derived/utils.js +46 -30
- package/lib/commonjs/derived/utils.js.map +1 -1
- package/lib/commonjs/index.js +1 -7
- package/lib/commonjs/index.js.map +1 -1
- package/lib/module/derived/styleHandler.js +22 -0
- package/lib/module/derived/styleHandler.js.map +1 -1
- package/lib/module/derived/useStyle.js +0 -6
- package/lib/module/derived/useStyle.js.map +1 -1
- package/lib/module/derived/utils.js +46 -30
- package/lib/module/derived/utils.js.map +1 -1
- package/lib/module/index.js +1 -7
- package/lib/module/index.js.map +1 -1
- package/lib/typescript/src/coreTypes.d.ts +6 -6
- package/lib/typescript/src/coreTypes.d.ts.map +1 -1
- package/lib/typescript/src/derived/styleHandler.d.ts.map +1 -1
- package/lib/typescript/src/derived/useStyle.d.ts.map +1 -1
- package/lib/typescript/src/derived/utils.d.ts +6 -9
- package/lib/typescript/src/derived/utils.d.ts.map +1 -1
- package/lib/typescript/src/index.d.ts +5 -3
- package/lib/typescript/src/index.d.ts.map +1 -1
- package/package.json +7 -7
- package/src/coreTypes.ts +15 -5
- package/src/derived/styleHandler.ts +11 -0
- package/src/derived/useStyle.ts +0 -6
- package/src/derived/utils.ts +47 -44
- package/src/index.ts +6 -8
package/src/derived/utils.ts
CHANGED
@@ -14,60 +14,61 @@ export function createLayout<T extends string>(styles: NodeTree<T>) {
|
|
14
14
|
return styles;
|
15
15
|
}
|
16
16
|
|
17
|
-
|
18
|
-
layout: Record<T, Node>;
|
19
|
-
rootKey: T;
|
20
|
-
|
21
|
-
constructor(rootKey: T) {
|
22
|
-
const config = Yoga.Config.create();
|
23
|
-
config.setPointScaleFactor(0);
|
24
|
-
const root = Yoga.Node.create(config);
|
25
|
-
this.rootKey = rootKey;
|
26
|
-
this.layout = {
|
27
|
-
[rootKey]: root,
|
28
|
-
} as Record<T, Node>;
|
29
|
-
}
|
30
|
-
|
31
|
-
addNodeTo(parentKey: T, key: T, index: number) {
|
32
|
-
const parent = this.layout[parentKey];
|
33
|
-
const child = Yoga.Node.create();
|
34
|
-
parent.insertChild(child, index);
|
35
|
-
this.layout[key] = child;
|
36
|
-
return child;
|
37
|
-
}
|
38
|
-
|
39
|
-
getNode(key: T) {
|
40
|
-
return this.layout[key];
|
41
|
-
}
|
42
|
-
|
43
|
-
free() {
|
44
|
-
this.getNode(this.rootKey).freeRecursive();
|
45
|
-
}
|
17
|
+
type TreeItem<T extends string> = NodeTree<T> | NodeTree<T>[];
|
46
18
|
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
19
|
+
function Layout<T extends string>(rootKey: T){
|
20
|
+
'worklet';
|
21
|
+
const config = Yoga.Config.create();
|
22
|
+
config.setPointScaleFactor(0);
|
23
|
+
const root = Yoga.Node.create(config);
|
24
|
+
const layout = {
|
25
|
+
[rootKey]: root,
|
26
|
+
} as Record<T, Node>;
|
27
|
+
return {
|
28
|
+
layout,
|
29
|
+
rootKey,
|
30
|
+
getNode: (key: T) => {
|
31
|
+
'worklet';
|
32
|
+
return layout[key];
|
33
|
+
},
|
34
|
+
addNodeTo: (parentKey: T, key: T, index: number) => {
|
35
|
+
'worklet';
|
36
|
+
const parent = layout[parentKey];
|
37
|
+
const child = Yoga.Node.create();
|
38
|
+
parent.insertChild(child, index);
|
39
|
+
layout[key] = child;
|
40
|
+
return child;
|
41
|
+
},
|
42
|
+
free: () => {
|
43
|
+
'worklet';
|
44
|
+
root.freeRecursive();
|
45
|
+
},
|
46
|
+
forEach: (cb: (node: Node, key: T) => void) => {
|
47
|
+
'worklet';
|
48
|
+
for (const key in layout) {
|
49
|
+
cb(layout[key], key);
|
50
|
+
}
|
51
|
+
},
|
52
|
+
};
|
52
53
|
}
|
53
54
|
|
54
|
-
type TreeItem<T extends string> = NodeTree<T> | NodeTree<T>[];
|
55
|
-
|
56
55
|
export function generateStyledLayout<T extends string>(layout: NodeTree<T>) {
|
57
|
-
|
56
|
+
'worklet';
|
57
|
+
const layoutTree = Layout(layout.key);
|
58
58
|
applyStyle(layoutTree.layout[layout.key], layout.style);
|
59
|
-
|
60
|
-
treeItem: TreeItem<
|
59
|
+
function _parse<U extends T>(
|
60
|
+
treeItem: TreeItem<U>,
|
61
61
|
index: number,
|
62
62
|
isArray: boolean,
|
63
|
-
parentKey:
|
63
|
+
parentKey: U | null
|
64
64
|
) {
|
65
|
+
'worklet';
|
65
66
|
if (isArray) {
|
66
|
-
(treeItem as NodeTree<
|
67
|
+
(treeItem as NodeTree<U>[]).forEach((o, i) => {
|
67
68
|
_parse(o, i, false, parentKey);
|
68
69
|
});
|
69
70
|
} else {
|
70
|
-
treeItem = treeItem as NodeTree<
|
71
|
+
treeItem = treeItem as NodeTree<U>;
|
71
72
|
if (parentKey !== null) {
|
72
73
|
const addedNode = layoutTree.addNodeTo(parentKey, treeItem.key, index);
|
73
74
|
applyStyle(addedNode, treeItem.style);
|
@@ -76,9 +77,11 @@ export function generateStyledLayout<T extends string>(layout: NodeTree<T>) {
|
|
76
77
|
_parse(treeItem.children, 0, true, treeItem.key);
|
77
78
|
}
|
78
79
|
}
|
79
|
-
|
80
|
+
|
80
81
|
return layoutTree;
|
81
|
-
}
|
82
|
+
}
|
83
|
+
|
84
|
+
_parse(layout, 0, false, null);
|
82
85
|
|
83
86
|
return layoutTree;
|
84
87
|
}
|
package/src/index.ts
CHANGED
@@ -1,18 +1,16 @@
|
|
1
1
|
import { NativeModules } from 'react-native';
|
2
|
-
import type { Yoga } from './coreTypes';
|
3
|
-
// import * as derived from './derived';
|
4
|
-
// import * as coreTypes from './coreTypes';
|
2
|
+
import type { Yoga as YogaType } from './coreTypes';
|
5
3
|
|
6
4
|
(function () {
|
7
5
|
NativeModules.YogaJSI.install();
|
8
6
|
})();
|
9
7
|
|
10
|
-
|
11
|
-
const
|
12
|
-
|
13
|
-
} = global;
|
8
|
+
declare global {
|
9
|
+
const Yoga: YogaType;
|
10
|
+
}
|
14
11
|
|
15
|
-
|
12
|
+
|
13
|
+
export default Yoga;
|
16
14
|
export * from './derived';
|
17
15
|
export * from './coreTypes';
|
18
16
|
|