@reactunity/renderer 0.8.1 → 0.9.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/dist/index.d.ts +2 -1
- package/dist/index.js +2 -1
- package/dist/src/helpers/dictionary-watcher.js +1 -1
- package/dist/src/helpers/watcher.d.ts +2 -0
- package/dist/src/helpers/watcher.js +15 -0
- package/dist/src/models/generated/react.d.ts +151 -218
- package/dist/src/models/generated/react.js +1 -1
- package/dist/src/models/properties/styles-enums.d.ts +1 -0
- package/dist/src/models/properties/styles.d.ts +3 -1
- package/dist/src/renderer/renderer.d.ts +10 -2
- package/dist/src/renderer/renderer.js +48 -38
- package/package.json +4 -4
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
export declare type FontWeight = 'thin' | 100 | 'extra-light' | 200 | 'light' | 300 | 'regular' | 400 | 'medium' | 500 | 'semi-bold' | 600 | 'bold' | 700 | 'heavy' | 800 | 'black' | 900;
|
|
2
2
|
export declare type FontStyles = 'normal' | 'bold' | 'italic' | 'underline' | 'lowercase' | 'uppercase' | 'smallcaps' | 'strikethrough' | 'superscript' | 'subscript' | 'highlight';
|
|
3
|
+
export declare type TextTransform = 'none' | 'lowercase' | 'uppercase' | 'smallcaps' | 'capitalize';
|
|
3
4
|
export declare type TextOverflowModes = 'overflow' | 'ellipsis' | 'masking' | 'truncate' | 'scroll-rect' | 'page' | 'linked';
|
|
4
5
|
export declare type PointerEvents = 'auto' | 'visible' | 'all' | 'none';
|
|
5
6
|
export declare type Visibility = 'visible' | 'hidden';
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { AnimationDirection, AnimationFillMode, AnimationPlayState, Appearance, BackgroundBlendMode, BackgroundSize, CursorType, FontStyles, FontWeight, NavigationMode, ObjectFit, PointerEvents, TextAlign, TextOverflowModes, TimingFunctionType, Visibility, WhiteSpace } from './styles-enums';
|
|
1
|
+
import { AnimationDirection, AnimationFillMode, AnimationPlayState, Appearance, BackgroundBlendMode, BackgroundSize, CursorType, FontStyles, FontWeight, NavigationMode, ObjectFit, PointerEvents, TextAlign, TextOverflowModes, TextTransform, TimingFunctionType, Visibility, WhiteSpace } from './styles-enums';
|
|
2
2
|
import { AssetReference, ColorAux, NumberAux, Vector2Aux, Vector3Aux } from './values';
|
|
3
3
|
import { YogaValue2Aux, YogaValueAux } from './yoga';
|
|
4
4
|
export interface RenderStyle {
|
|
@@ -40,6 +40,7 @@ export interface RenderStyle {
|
|
|
40
40
|
objectPosition?: YogaValue2Aux;
|
|
41
41
|
transformOrigin?: Vector2Aux;
|
|
42
42
|
translate?: YogaValue2Aux;
|
|
43
|
+
translateZ?: YogaValueAux;
|
|
43
44
|
scale?: Vector2Aux;
|
|
44
45
|
rotate?: Vector3Aux;
|
|
45
46
|
stateDuration?: number | string;
|
|
@@ -47,6 +48,7 @@ export interface RenderStyle {
|
|
|
47
48
|
fontFamily?: AssetReference;
|
|
48
49
|
fontWeight?: FontWeight;
|
|
49
50
|
fontStyle?: FontStyles;
|
|
51
|
+
textTransform?: TextTransform;
|
|
50
52
|
fontSize?: YogaValueAux;
|
|
51
53
|
textOverflow?: TextOverflowModes;
|
|
52
54
|
textAlign?: TextAlign;
|
|
@@ -1,5 +1,13 @@
|
|
|
1
|
-
import
|
|
1
|
+
import * as React from 'react';
|
|
2
2
|
import { NativeContainerInstance } from '../models/renderer';
|
|
3
|
+
interface RenderOptions {
|
|
4
|
+
hostContainer?: NativeContainerInstance;
|
|
5
|
+
disableHelpers?: boolean;
|
|
6
|
+
mode?: 'legacy' | 'concurrent';
|
|
7
|
+
}
|
|
3
8
|
export declare const Renderer: {
|
|
4
|
-
render(element: React.ReactNode,
|
|
9
|
+
render(element: React.ReactNode, options?: RenderOptions): void;
|
|
5
10
|
};
|
|
11
|
+
export declare const batchedUpdates: <A, R>(fn: (a: A) => R, a: A) => R;
|
|
12
|
+
export declare const flushSync: <A, R>(fn: (a: A) => R, a: A) => R;
|
|
13
|
+
export {};
|
|
@@ -13,8 +13,18 @@ import { createElement } from 'react';
|
|
|
13
13
|
import * as Reconciler from 'react-reconciler';
|
|
14
14
|
import { DefaultView } from '../views/default-view';
|
|
15
15
|
import { diffProperties, styleStringSymbol } from './diffing';
|
|
16
|
+
var LegacyRoot = 0;
|
|
17
|
+
var ConcurrentRoot = 1;
|
|
16
18
|
var hostContext = {};
|
|
17
19
|
var childContext = {};
|
|
20
|
+
var DiscreteEventPriority = 1;
|
|
21
|
+
var ContinuousEventPriority = 4;
|
|
22
|
+
var DefaultEventPriority = 16;
|
|
23
|
+
var eventPriorities = {
|
|
24
|
+
discrete: DiscreteEventPriority,
|
|
25
|
+
continuous: ContinuousEventPriority,
|
|
26
|
+
default: DefaultEventPriority,
|
|
27
|
+
};
|
|
18
28
|
var textTypes = {
|
|
19
29
|
text: true,
|
|
20
30
|
icon: true,
|
|
@@ -23,7 +33,7 @@ var textTypes = {
|
|
|
23
33
|
};
|
|
24
34
|
function getAllowedProps(props, type) {
|
|
25
35
|
var children = props.children, tag = props.tag, rest = __rest(props, ["children", "tag"]);
|
|
26
|
-
if (textTypes[type]) {
|
|
36
|
+
if (textTypes[type] && 'children' in props) {
|
|
27
37
|
rest.children = (!children || typeof children === 'boolean') ? null : Array.isArray(children) ? children.join('') : children + '';
|
|
28
38
|
}
|
|
29
39
|
if (typeof props.style === 'string')
|
|
@@ -31,43 +41,44 @@ function getAllowedProps(props, type) {
|
|
|
31
41
|
return rest;
|
|
32
42
|
}
|
|
33
43
|
var hostConfig = {
|
|
34
|
-
getRootHostContext: function (
|
|
35
|
-
getChildHostContext: function (
|
|
44
|
+
getRootHostContext: function () { return hostContext; },
|
|
45
|
+
getChildHostContext: function () { return childContext; },
|
|
36
46
|
getPublicInstance: function (instance) { return instance; },
|
|
37
|
-
prepareForCommit: function (containerInfo) { return null; },
|
|
38
|
-
resetAfterCommit: function (containerInfo) { return null; },
|
|
39
|
-
clearContainer: function () { return null; },
|
|
40
47
|
now: Date.now,
|
|
48
|
+
supportsMutation: true,
|
|
41
49
|
supportsHydration: false,
|
|
42
50
|
supportsPersistence: false,
|
|
51
|
+
supportsMicrotasks: false,
|
|
52
|
+
supportsTestSelectors: false,
|
|
43
53
|
isPrimaryRenderer: true,
|
|
44
|
-
|
|
54
|
+
warnsIfNotActing: true,
|
|
55
|
+
prepareForCommit: function () { return null; },
|
|
56
|
+
resetAfterCommit: function () { },
|
|
57
|
+
clearContainer: function () { },
|
|
58
|
+
shouldDeprioritizeSubtree: function () { return false; },
|
|
59
|
+
createInstance: function (type, props, rootContainerInstance) {
|
|
45
60
|
var aProps = getAllowedProps(props, type);
|
|
46
61
|
var children = aProps.children || null;
|
|
47
62
|
delete aProps.children;
|
|
48
63
|
return UnityBridge.createElement(props.tag || type, children, rootContainerInstance, aProps);
|
|
49
64
|
},
|
|
50
|
-
createTextInstance: function (text, rootContainerInstance
|
|
65
|
+
createTextInstance: function (text, rootContainerInstance) {
|
|
51
66
|
return UnityBridge.createText(text, rootContainerInstance);
|
|
52
67
|
},
|
|
53
68
|
appendInitialChild: function (parent, child) { UnityBridge.appendChild(parent, child); },
|
|
54
|
-
finalizeInitialChildren: function (
|
|
55
|
-
|
|
56
|
-
},
|
|
57
|
-
commitMount: function (instance, type, newProps, internalInstanceHandle) { },
|
|
58
|
-
shouldSetTextContent: function (type, props) { return textTypes[type]; },
|
|
59
|
-
shouldDeprioritizeSubtree: function (type, props) { return false; },
|
|
69
|
+
finalizeInitialChildren: function () { return false; },
|
|
70
|
+
commitMount: function () { },
|
|
71
|
+
shouldSetTextContent: function (type) { return textTypes[type]; },
|
|
60
72
|
// -------------------
|
|
61
73
|
// Mutation
|
|
62
74
|
// -------------------
|
|
63
|
-
|
|
64
|
-
prepareUpdate: function (instance, type, oldProps, newProps, rootContainerInstance, hostContext) {
|
|
75
|
+
prepareUpdate: function (instance, type, oldProps, newProps) {
|
|
65
76
|
return diffProperties(oldProps, newProps);
|
|
66
77
|
},
|
|
67
|
-
commitUpdate: function (instance, updatePayload, type
|
|
78
|
+
commitUpdate: function (instance, updatePayload, type) {
|
|
68
79
|
UnityBridge.applyUpdate(instance, getAllowedProps(updatePayload, type), type);
|
|
69
80
|
},
|
|
70
|
-
resetTextContent: function (
|
|
81
|
+
resetTextContent: function () { return console.log('resetTextContent'); },
|
|
71
82
|
commitTextUpdate: function (textInstance, oldText, newText) { UnityBridge.setText(textInstance, newText); },
|
|
72
83
|
appendChild: function (parent, child) { return UnityBridge.appendChild(parent, child); },
|
|
73
84
|
appendChildToContainer: function (parent, child) { return UnityBridge.appendChildToContainer(parent, child); },
|
|
@@ -78,35 +89,34 @@ var hostConfig = {
|
|
|
78
89
|
// Required for Suspense
|
|
79
90
|
// TODO: implement
|
|
80
91
|
preparePortalMount: function () { },
|
|
81
|
-
hideInstance: function (
|
|
82
|
-
},
|
|
83
|
-
|
|
84
|
-
},
|
|
85
|
-
|
|
86
|
-
},
|
|
87
|
-
unhideTextInstance: function (textInstance, text) {
|
|
88
|
-
},
|
|
92
|
+
hideInstance: function () { },
|
|
93
|
+
hideTextInstance: function () { },
|
|
94
|
+
unhideInstance: function () { },
|
|
95
|
+
unhideTextInstance: function () { },
|
|
96
|
+
detachDeletedInstance: function () { },
|
|
89
97
|
// -------------------
|
|
90
98
|
// Scheduling
|
|
91
99
|
// -------------------
|
|
92
|
-
|
|
93
|
-
cancelDeferredCallback: function (callBackID) { clearTimeout(callBackID); },
|
|
100
|
+
getCurrentEventPriority: function () { return eventPriorities.default; },
|
|
94
101
|
noTimeout: -1,
|
|
95
102
|
scheduleTimeout: function (callback, timeout) { return setTimeout(callback, timeout); },
|
|
96
|
-
cancelTimeout: function (handle) { clearTimeout(handle); },
|
|
97
|
-
queueMicrotask: function (callback) { return setTimeout(callback, 0); },
|
|
103
|
+
cancelTimeout: function (handle) { return clearTimeout(handle); },
|
|
98
104
|
};
|
|
99
|
-
var
|
|
105
|
+
var reconciler = Reconciler(hostConfig);
|
|
100
106
|
var containerMap = new Map();
|
|
101
107
|
export var Renderer = {
|
|
102
|
-
render: function (element,
|
|
103
|
-
if (
|
|
104
|
-
|
|
108
|
+
render: function (element, options) {
|
|
109
|
+
if (options === void 0) { options = {}; }
|
|
110
|
+
var hostContainer = (options === null || options === void 0 ? void 0 : options.hostContainer) || HostContainer;
|
|
105
111
|
var hostRoot = containerMap.get(hostContainer);
|
|
106
|
-
if (!hostRoot)
|
|
107
|
-
|
|
108
|
-
|
|
112
|
+
if (!hostRoot) {
|
|
113
|
+
hostRoot = reconciler.createContainer(hostContainer, (options === null || options === void 0 ? void 0 : options.mode) === 'legacy' ? LegacyRoot : ConcurrentRoot, false, null);
|
|
114
|
+
containerMap.set(hostContainer, hostRoot);
|
|
115
|
+
}
|
|
116
|
+
if (!(options === null || options === void 0 ? void 0 : options.disableHelpers))
|
|
109
117
|
element = createElement(DefaultView, null, element);
|
|
110
|
-
|
|
118
|
+
reconciler.updateContainer(element, hostRoot, null);
|
|
111
119
|
},
|
|
112
120
|
};
|
|
121
|
+
export var batchedUpdates = reconciler.batchedUpdates;
|
|
122
|
+
export var flushSync = reconciler.flushSync;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@reactunity/renderer",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.9.2",
|
|
4
4
|
"description": "React renderer for Unity3D",
|
|
5
5
|
"types": "dist/index.d.ts",
|
|
6
6
|
"typings": "dist/index.d.ts",
|
|
@@ -58,12 +58,12 @@
|
|
|
58
58
|
"react-reconciler": "^0.26.2"
|
|
59
59
|
},
|
|
60
60
|
"peerDependencies": {
|
|
61
|
-
"react": "
|
|
61
|
+
"react": ">=17"
|
|
62
62
|
},
|
|
63
63
|
"devDependencies": {
|
|
64
|
-
"@reactunity/scripts": "^0.
|
|
64
|
+
"@reactunity/scripts": "^0.9.0",
|
|
65
65
|
"@types/react-reconciler": "^0.26.4",
|
|
66
66
|
"rimraf": "^3.0.2",
|
|
67
|
-
"typescript": "^4.
|
|
67
|
+
"typescript": "^4.5.5"
|
|
68
68
|
}
|
|
69
69
|
}
|