@reactunity/renderer 0.9.2 → 0.10.0
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/src/helpers/dictionary-watcher.d.ts +14 -2
- package/dist/src/helpers/dictionary-watcher.js +28 -21
- package/dist/src/helpers/watcher.js +10 -11
- package/dist/src/models/environment/index.d.ts +1 -0
- package/dist/src/models/generated/react.d.ts +398 -83
- package/dist/src/models/generated/react.js +1 -1
- package/dist/src/models/properties/styles.d.ts +6 -6
- package/dist/src/renderer/async/callbacks.d.ts +6 -0
- package/dist/src/renderer/async/callbacks.js +38 -0
- package/dist/src/renderer/async/commands.d.ts +45 -0
- package/dist/src/renderer/async/commands.js +1 -0
- package/dist/src/renderer/async/objects.d.ts +8 -0
- package/dist/src/renderer/async/objects.js +31 -0
- package/dist/src/renderer/async/reconciler.d.ts +9 -0
- package/dist/src/renderer/async/reconciler.js +135 -0
- package/dist/src/renderer/async/types.d.ts +19 -0
- package/dist/src/renderer/async/types.js +1 -0
- package/dist/src/renderer/constants.d.ts +23 -0
- package/dist/src/renderer/constants.js +49 -0
- package/dist/src/renderer/diffing.js +39 -13
- package/dist/src/renderer/renderer.d.ts +9 -1
- package/dist/src/renderer/renderer.js +73 -111
- package/dist/src/renderer/sync/reconciler.d.ts +2 -0
- package/dist/src/renderer/sync/reconciler.js +35 -0
- package/dist/src/version.d.ts +1 -0
- package/dist/src/version.js +1 -0
- package/dist/src/views/default-view.d.ts +2 -1
- package/dist/src/views/default-view.js +4 -3
- package/dist/src/views/error-boundary.d.ts +1 -1
- package/dist/src/views/error-boundary.js +1 -1
- package/package.json +9 -9
- package/version.js +3 -0
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { AnimationDirection, AnimationFillMode, AnimationPlayState, Appearance, BackgroundBlendMode, BackgroundSize, CursorType, FontStyles, FontWeight, NavigationMode, ObjectFit, PointerEvents, TextAlign, TextOverflowModes, TextTransform, TimingFunctionType, Visibility, WhiteSpace } from './styles-enums';
|
|
2
|
-
import { AssetReference, ColorAux, NumberAux, Vector2Aux, Vector3Aux } from './values';
|
|
2
|
+
import { Array2Aux, AssetReference, ColorAux, NumberAux, Vector2Aux, Vector3Aux } from './values';
|
|
3
3
|
import { YogaValue2Aux, YogaValueAux } from './yoga';
|
|
4
4
|
export interface RenderStyle {
|
|
5
5
|
opacity?: NumberAux;
|
|
@@ -25,11 +25,11 @@ export interface RenderStyle {
|
|
|
25
25
|
maskSize?: BackgroundSize | YogaValue2Aux;
|
|
26
26
|
maskRepeatX?: YogaValueAux;
|
|
27
27
|
maskRepeatY?: YogaValueAux;
|
|
28
|
-
borderRadius?:
|
|
29
|
-
borderTopLeftRadius?:
|
|
30
|
-
borderTopRightRadius?:
|
|
31
|
-
borderBottomRightRadius?:
|
|
32
|
-
borderBottomLeftRadius?:
|
|
28
|
+
borderRadius?: Array2Aux<YogaValueAux> | string;
|
|
29
|
+
borderTopLeftRadius?: Array2Aux<YogaValueAux>;
|
|
30
|
+
borderTopRightRadius?: Array2Aux<YogaValueAux>;
|
|
31
|
+
borderBottomRightRadius?: Array2Aux<YogaValueAux>;
|
|
32
|
+
borderBottomLeftRadius?: Array2Aux<YogaValueAux>;
|
|
33
33
|
borderColor?: ColorAux;
|
|
34
34
|
borderTopColor?: ColorAux;
|
|
35
35
|
borderRightColor?: ColorAux;
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
var __extends = (this && this.__extends) || (function () {
|
|
2
|
+
var extendStatics = function (d, b) {
|
|
3
|
+
extendStatics = Object.setPrototypeOf ||
|
|
4
|
+
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
5
|
+
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
|
6
|
+
return extendStatics(d, b);
|
|
7
|
+
};
|
|
8
|
+
return function (d, b) {
|
|
9
|
+
if (typeof b !== "function" && b !== null)
|
|
10
|
+
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
|
11
|
+
extendStatics(d, b);
|
|
12
|
+
function __() { this.constructor = d; }
|
|
13
|
+
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
14
|
+
};
|
|
15
|
+
})();
|
|
16
|
+
import { ObjectsRepo } from './objects';
|
|
17
|
+
var CallbacksRepo = /** @class */ (function (_super) {
|
|
18
|
+
__extends(CallbacksRepo, _super);
|
|
19
|
+
function CallbacksRepo() {
|
|
20
|
+
var _this = _super.call(this) || this;
|
|
21
|
+
_this.call = function (ind, args) {
|
|
22
|
+
var cb = _this.getObject(ind);
|
|
23
|
+
if ('Length' in args) {
|
|
24
|
+
var newArgs = [];
|
|
25
|
+
var length = args['Length'];
|
|
26
|
+
for (var index = 0; index < length; index++) {
|
|
27
|
+
var element = args[index];
|
|
28
|
+
newArgs.push(element);
|
|
29
|
+
}
|
|
30
|
+
args = newArgs;
|
|
31
|
+
}
|
|
32
|
+
return cb.apply(null, args);
|
|
33
|
+
};
|
|
34
|
+
return _this;
|
|
35
|
+
}
|
|
36
|
+
return CallbacksRepo;
|
|
37
|
+
}(ObjectsRepo));
|
|
38
|
+
export { CallbacksRepo };
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
export declare type BatchUpdateProps = {
|
|
2
|
+
[key: string]: string | number | object;
|
|
3
|
+
};
|
|
4
|
+
export declare type AsyncCallback = (...args: any[]) => any;
|
|
5
|
+
export declare type BatchUpdateCallbacks = {
|
|
6
|
+
[key: string]: number;
|
|
7
|
+
};
|
|
8
|
+
declare type ApplyUpdatesParams = {
|
|
9
|
+
t: string;
|
|
10
|
+
r: number;
|
|
11
|
+
c?: string;
|
|
12
|
+
p?: BatchUpdateProps;
|
|
13
|
+
e?: BatchUpdateCallbacks;
|
|
14
|
+
o?: BatchUpdateCallbacks;
|
|
15
|
+
};
|
|
16
|
+
export declare type CreateInstanceCommand = ['c', ApplyUpdatesParams];
|
|
17
|
+
export declare type CreateTextInstanceCommand = ['t', {
|
|
18
|
+
r: number;
|
|
19
|
+
c?: string;
|
|
20
|
+
}];
|
|
21
|
+
export declare type AppendChildCommand = ['a', {
|
|
22
|
+
p: number;
|
|
23
|
+
c: number;
|
|
24
|
+
}];
|
|
25
|
+
export declare type RemoveChildCommand = ['r', {
|
|
26
|
+
p: number;
|
|
27
|
+
c: number;
|
|
28
|
+
}];
|
|
29
|
+
export declare type InsertChildCommand = ['i', {
|
|
30
|
+
p: number;
|
|
31
|
+
c: number;
|
|
32
|
+
i?: number;
|
|
33
|
+
}];
|
|
34
|
+
export declare type ApplyUpdatesCommand = ['u', ApplyUpdatesParams];
|
|
35
|
+
export declare type TextUpdateCommand = ['x', {
|
|
36
|
+
r: number;
|
|
37
|
+
c: string;
|
|
38
|
+
}];
|
|
39
|
+
export declare type ToggleHideCommand = ['h', {
|
|
40
|
+
r: number;
|
|
41
|
+
h: boolean;
|
|
42
|
+
}];
|
|
43
|
+
export declare type ClearContainerCommand = ['o'];
|
|
44
|
+
export declare type BatchCommand = CreateInstanceCommand | CreateTextInstanceCommand | AppendChildCommand | RemoveChildCommand | InsertChildCommand | ApplyUpdatesCommand | TextUpdateCommand | ToggleHideCommand | ClearContainerCommand | null;
|
|
45
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
var ObjectsRepo = /** @class */ (function () {
|
|
2
|
+
function ObjectsRepo() {
|
|
3
|
+
var _this = this;
|
|
4
|
+
this.indices = [{}];
|
|
5
|
+
this.objects = new WeakMap();
|
|
6
|
+
this.setObject = function (index, item) {
|
|
7
|
+
var it = _this.indices[index];
|
|
8
|
+
if (!it) {
|
|
9
|
+
it = _this.indices[index] = {};
|
|
10
|
+
}
|
|
11
|
+
_this.objects.set(it, item);
|
|
12
|
+
};
|
|
13
|
+
this.addObject = function (item) {
|
|
14
|
+
if (!item)
|
|
15
|
+
return -1;
|
|
16
|
+
var it = {};
|
|
17
|
+
var ind = _this.indices.length;
|
|
18
|
+
_this.indices.push(it);
|
|
19
|
+
_this.objects.set(it, item);
|
|
20
|
+
return ind;
|
|
21
|
+
};
|
|
22
|
+
this.getObject = function (index) {
|
|
23
|
+
if (index < 0)
|
|
24
|
+
return undefined;
|
|
25
|
+
var it = _this.indices[index];
|
|
26
|
+
return _this.objects.get(it);
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
return ObjectsRepo;
|
|
30
|
+
}());
|
|
31
|
+
export { ObjectsRepo };
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import * as Reconciler from 'react-reconciler';
|
|
2
|
+
import { ObjectsRepo } from './objects';
|
|
3
|
+
import { AsyncHostContext } from './types';
|
|
4
|
+
export declare const asyncReconciler: Reconciler.Reconciler<AsyncHostContext & {
|
|
5
|
+
refId: number;
|
|
6
|
+
} & {
|
|
7
|
+
component: import("../../..").ReactUnity.IReactComponent;
|
|
8
|
+
fiberCache: ObjectsRepo<any>;
|
|
9
|
+
}, import("./types").AsyncNativeInstance, import("./types").AsyncNativeInstance, import("./types").AsyncNativeInstance, import("../../..").ReactUnity.IReactComponent>;
|
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
var __assign = (this && this.__assign) || function () {
|
|
2
|
+
__assign = Object.assign || function(t) {
|
|
3
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
4
|
+
s = arguments[i];
|
|
5
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
6
|
+
t[p] = s[p];
|
|
7
|
+
}
|
|
8
|
+
return t;
|
|
9
|
+
};
|
|
10
|
+
return __assign.apply(this, arguments);
|
|
11
|
+
};
|
|
12
|
+
import * as Reconciler from 'react-reconciler';
|
|
13
|
+
import { commonReconciler, getAllowedProps, textTypes } from '../constants';
|
|
14
|
+
import { diffProperties } from '../diffing';
|
|
15
|
+
import { CallbacksRepo } from './callbacks';
|
|
16
|
+
import { ObjectsRepo } from './objects';
|
|
17
|
+
var refId = 0;
|
|
18
|
+
var callbacks = new CallbacksRepo();
|
|
19
|
+
var objects = new ObjectsRepo();
|
|
20
|
+
// Separates properties in 3 categories: regular props, callbacks and non-serializable objects
|
|
21
|
+
function partitionProps(props) {
|
|
22
|
+
var res = {};
|
|
23
|
+
for (var key in props) {
|
|
24
|
+
if (Object.prototype.hasOwnProperty.call(props, key)) {
|
|
25
|
+
var value = props[key];
|
|
26
|
+
if (value == null) {
|
|
27
|
+
(res.p || (res.p = {}))[key] = null;
|
|
28
|
+
}
|
|
29
|
+
else if (key === 'style') {
|
|
30
|
+
(res.p || (res.p = {}))[key] = partitionProps(value);
|
|
31
|
+
}
|
|
32
|
+
else if (typeof value === 'function') {
|
|
33
|
+
var ind = callbacks.addObject(value);
|
|
34
|
+
(res.e || (res.e = {}))[key] = ind;
|
|
35
|
+
}
|
|
36
|
+
else if (typeof value === 'object') {
|
|
37
|
+
var ind = objects.addObject(value);
|
|
38
|
+
(res.o || (res.o = {}))[key] = ind;
|
|
39
|
+
}
|
|
40
|
+
else {
|
|
41
|
+
(res.p || (res.p = {}))[key] = value;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
return res;
|
|
46
|
+
}
|
|
47
|
+
var ctxMap = new Map();
|
|
48
|
+
var hostConfig = __assign(__assign({}, commonReconciler), { getRootHostContext: function (rootContainer) {
|
|
49
|
+
var context = rootContainer.context;
|
|
50
|
+
if (rootContainer.refId < 0) {
|
|
51
|
+
refId++;
|
|
52
|
+
rootContainer.context.SetRef(refId, rootContainer.component);
|
|
53
|
+
rootContainer.refId = refId;
|
|
54
|
+
}
|
|
55
|
+
var existing = ctxMap.get(context);
|
|
56
|
+
if (existing)
|
|
57
|
+
return existing;
|
|
58
|
+
var commands = rootContainer.commands;
|
|
59
|
+
var flushCommands = function () {
|
|
60
|
+
var serialized = JSON.stringify(commands);
|
|
61
|
+
commands.length = 0;
|
|
62
|
+
return serialized;
|
|
63
|
+
};
|
|
64
|
+
var fireEventByRef = function (ind, args) {
|
|
65
|
+
return callbacks.call(ind, args);
|
|
66
|
+
};
|
|
67
|
+
var getObjectRef = function (ind) {
|
|
68
|
+
return objects.getObject(ind);
|
|
69
|
+
};
|
|
70
|
+
var getEventAsObjectRef = function (ind) {
|
|
71
|
+
return callbacks.getObject(ind);
|
|
72
|
+
};
|
|
73
|
+
context.BindCommands(flushCommands, fireEventByRef, getObjectRef, getEventAsObjectRef);
|
|
74
|
+
var ctx = {
|
|
75
|
+
context: context,
|
|
76
|
+
commands: commands,
|
|
77
|
+
};
|
|
78
|
+
ctxMap.set(context, ctx);
|
|
79
|
+
return ctx;
|
|
80
|
+
}, getChildHostContext: function (parentCtx) {
|
|
81
|
+
return parentCtx;
|
|
82
|
+
}, getPublicInstance: function (instance) {
|
|
83
|
+
return instance.context.GetRef(instance.refId, instance.commands.length > 0);
|
|
84
|
+
}, supportsMutation: true, supportsHydration: false, supportsPersistence: false, supportsMicrotasks: true, supportsTestSelectors: false, isPrimaryRenderer: true, warnsIfNotActing: true, prepareForCommit: function () { return null; }, resetAfterCommit: function () { }, shouldDeprioritizeSubtree: function () { return false; }, clearContainer: function (container) {
|
|
85
|
+
UnityBridge.clearContainer(container);
|
|
86
|
+
}, createInstance: function (type, props, rootContainer, ctx, internalHandle) {
|
|
87
|
+
refId++;
|
|
88
|
+
var aProps = getAllowedProps(props, type);
|
|
89
|
+
ctx.commands.push(['c', __assign({ t: type, r: refId }, partitionProps(aProps))]);
|
|
90
|
+
if (rootContainer.fiberCache)
|
|
91
|
+
rootContainer.fiberCache.setObject(refId, internalHandle);
|
|
92
|
+
return __assign(__assign({}, ctx), { refId: refId });
|
|
93
|
+
}, createTextInstance: function (text, rootContainer, ctx, internalHandle) {
|
|
94
|
+
refId++;
|
|
95
|
+
ctx.commands.push(['t', { r: refId, c: text }]);
|
|
96
|
+
if (rootContainer.fiberCache)
|
|
97
|
+
rootContainer.fiberCache.setObject(refId, internalHandle);
|
|
98
|
+
return __assign(__assign({}, ctx), { refId: refId });
|
|
99
|
+
}, appendInitialChild: function (parent, child) {
|
|
100
|
+
parent.commands.push(['a', { p: parent.refId, c: child.refId }]);
|
|
101
|
+
}, finalizeInitialChildren: function () { return false; }, commitMount: function (instance) { }, shouldSetTextContent: function (type) { return textTypes[type]; },
|
|
102
|
+
// -------------------
|
|
103
|
+
// Mutation
|
|
104
|
+
// -------------------
|
|
105
|
+
prepareUpdate: function (instance, type, oldProps, newProps) {
|
|
106
|
+
return diffProperties(oldProps, newProps);
|
|
107
|
+
}, commitUpdate: function (instance, updatePayload, type) {
|
|
108
|
+
var props = getAllowedProps(updatePayload, type);
|
|
109
|
+
instance.commands.push(['u', __assign({ r: instance.refId, t: type }, partitionProps(props))]);
|
|
110
|
+
}, commitTextUpdate: function (textInstance, oldText, newText) {
|
|
111
|
+
textInstance.commands.push(['x', { r: textInstance.refId, c: newText }]);
|
|
112
|
+
}, appendChild: function (parent, child) {
|
|
113
|
+
child.commands.push(['a', { p: parent.refId, c: child.refId }]);
|
|
114
|
+
}, appendChildToContainer: function (parent, child) {
|
|
115
|
+
child.commands.push(['a', { p: parent.refId, c: child.refId }]);
|
|
116
|
+
}, insertBefore: function (parent, child, beforeChild) {
|
|
117
|
+
child.commands.push(['i', { p: parent.refId, c: child.refId, i: beforeChild.refId }]);
|
|
118
|
+
}, insertInContainerBefore: function (parent, child, beforeChild) {
|
|
119
|
+
child.commands.push(['i', { p: parent.refId, c: child.refId, i: beforeChild.refId }]);
|
|
120
|
+
}, removeChild: function (parent, child) {
|
|
121
|
+
child.commands.push(['r', { p: parent.refId, c: child.refId }]);
|
|
122
|
+
}, removeChildFromContainer: function (parent, child) {
|
|
123
|
+
child.commands.push(['r', { p: parent.refId, c: child.refId }]);
|
|
124
|
+
}, resetTextContent: function () { }, preparePortalMount: function () { }, detachDeletedInstance: function () { },
|
|
125
|
+
// Required for Suspense
|
|
126
|
+
hideInstance: function (instance) {
|
|
127
|
+
instance.commands.push(['h', { r: instance.refId, h: true }]);
|
|
128
|
+
}, hideTextInstance: function (instance) {
|
|
129
|
+
instance.commands.push(['h', { r: instance.refId, h: true }]);
|
|
130
|
+
}, unhideInstance: function (instance) {
|
|
131
|
+
instance.commands.push(['h', { r: instance.refId, h: false }]);
|
|
132
|
+
}, unhideTextInstance: function (instance) {
|
|
133
|
+
instance.commands.push(['h', { r: instance.refId, h: false }]);
|
|
134
|
+
} });
|
|
135
|
+
export var asyncReconciler = Reconciler(hostConfig);
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import * as Reconciler from 'react-reconciler';
|
|
2
|
+
import { ReactUnity } from '../../models/generated';
|
|
3
|
+
import { ChildSet, HydratableInstance, InstanceTag, NoTimeout, Props, TimeoutHandle, UpdatePayload } from '../../models/renderer';
|
|
4
|
+
import { BatchCommand } from './commands';
|
|
5
|
+
import { ObjectsRepo } from './objects';
|
|
6
|
+
export declare type AsyncHostContext = {
|
|
7
|
+
context: ReactUnity.ReactContext;
|
|
8
|
+
commands: BatchCommand[];
|
|
9
|
+
};
|
|
10
|
+
export declare type AsyncNativeInstance = AsyncHostContext & {
|
|
11
|
+
refId: number;
|
|
12
|
+
};
|
|
13
|
+
declare type AsyncContainerInstance = AsyncNativeInstance & {
|
|
14
|
+
component: ReactUnity.IReactComponent;
|
|
15
|
+
fiberCache: ObjectsRepo | null;
|
|
16
|
+
};
|
|
17
|
+
declare type AsyncPublicInstance = ReactUnity.IReactComponent;
|
|
18
|
+
export declare type AsyncReconcilerConfig = Reconciler.HostConfig<InstanceTag, Props, AsyncContainerInstance, AsyncNativeInstance, AsyncNativeInstance, AsyncNativeInstance, HydratableInstance, AsyncPublicInstance, AsyncHostContext, UpdatePayload, ChildSet, TimeoutHandle, NoTimeout>;
|
|
19
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
export declare const hideClass = "react-unity__renderer__hidden";
|
|
2
|
+
export declare const eventPriorities: {
|
|
3
|
+
discrete: number;
|
|
4
|
+
continuous: number;
|
|
5
|
+
default: number;
|
|
6
|
+
idle: number;
|
|
7
|
+
};
|
|
8
|
+
export declare const textTypes: {
|
|
9
|
+
text: boolean;
|
|
10
|
+
icon: boolean;
|
|
11
|
+
style: boolean;
|
|
12
|
+
script: boolean;
|
|
13
|
+
};
|
|
14
|
+
export declare function getAllowedProps(props: any, type: any): any;
|
|
15
|
+
export declare const commonReconciler: {
|
|
16
|
+
now: () => number;
|
|
17
|
+
getCurrentEventPriority: () => number;
|
|
18
|
+
noTimeout: -1;
|
|
19
|
+
scheduleTimeout: (callback: any, delay: any) => number;
|
|
20
|
+
scheduleMicrotask: (callback: (...args: any[]) => any) => void;
|
|
21
|
+
cancelTimeout: (handle: any) => void;
|
|
22
|
+
};
|
|
23
|
+
export declare const isDevelopment: boolean;
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
var __rest = (this && this.__rest) || function (s, e) {
|
|
2
|
+
var t = {};
|
|
3
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
4
|
+
t[p] = s[p];
|
|
5
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
6
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
7
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
8
|
+
t[p[i]] = s[p[i]];
|
|
9
|
+
}
|
|
10
|
+
return t;
|
|
11
|
+
};
|
|
12
|
+
import { ContinuousEventPriority, DefaultEventPriority, DiscreteEventPriority, IdleEventPriority } from 'react-reconciler/constants';
|
|
13
|
+
import { styleStringSymbol } from './diffing';
|
|
14
|
+
export var hideClass = 'react-unity__renderer__hidden';
|
|
15
|
+
export var eventPriorities = {
|
|
16
|
+
discrete: DiscreteEventPriority,
|
|
17
|
+
continuous: ContinuousEventPriority,
|
|
18
|
+
default: DefaultEventPriority,
|
|
19
|
+
idle: IdleEventPriority,
|
|
20
|
+
};
|
|
21
|
+
export var textTypes = {
|
|
22
|
+
text: true,
|
|
23
|
+
icon: true,
|
|
24
|
+
style: true,
|
|
25
|
+
script: true,
|
|
26
|
+
};
|
|
27
|
+
export function getAllowedProps(props, type) {
|
|
28
|
+
var children = props.children, tag = props.tag, rest = __rest(props, ["children", "tag"]);
|
|
29
|
+
if (textTypes[type] && 'children' in props) {
|
|
30
|
+
rest.children = (!children || typeof children === 'boolean') ? null : Array.isArray(children) ? children.join('') : children + '';
|
|
31
|
+
}
|
|
32
|
+
if (typeof props.style === 'string')
|
|
33
|
+
rest[styleStringSymbol] = props.style;
|
|
34
|
+
return rest;
|
|
35
|
+
}
|
|
36
|
+
export var commonReconciler = {
|
|
37
|
+
// -------------------
|
|
38
|
+
// Scheduling
|
|
39
|
+
// -------------------
|
|
40
|
+
now: Date.now,
|
|
41
|
+
getCurrentEventPriority: function () { return UnityBridge.CurrentEventPriority || eventPriorities.default; },
|
|
42
|
+
noTimeout: -1,
|
|
43
|
+
scheduleTimeout: function (callback, delay) { return setTimeout(callback, delay); },
|
|
44
|
+
scheduleMicrotask: typeof queueMicrotask === 'function' ? queueMicrotask :
|
|
45
|
+
function (callback) { return Promise.resolve(null).then(callback)
|
|
46
|
+
.catch(function (error) { return setTimeout(function () { throw error; }, 0); }); },
|
|
47
|
+
cancelTimeout: function (handle) { return clearTimeout(handle); },
|
|
48
|
+
};
|
|
49
|
+
export var isDevelopment = process.env.NODE_ENV === 'development';
|
|
@@ -6,26 +6,31 @@ export function diffProperties(lastProps, nextProps, deepDiffing) {
|
|
|
6
6
|
var updatePayload = null;
|
|
7
7
|
var propKey;
|
|
8
8
|
for (propKey in lastProps) {
|
|
9
|
+
// This loop is for removing properties that existed in the previous properties, but not on current
|
|
9
10
|
if (nextProps.hasOwnProperty(propKey)
|
|
10
11
|
|| !lastProps.hasOwnProperty(propKey)
|
|
11
12
|
|| lastProps[propKey] == null) {
|
|
12
13
|
continue;
|
|
13
14
|
}
|
|
14
15
|
var prop = null;
|
|
16
|
+
// If style existed in the previous properties as string, set it to null
|
|
15
17
|
if (propKey === 'style' && typeof lastProps.style === 'string') {
|
|
16
18
|
(updatePayload = updatePayload || {})[styleStringSymbol] = null;
|
|
17
19
|
}
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
20
|
+
else {
|
|
21
|
+
var depth = deepDiffing > 0 ? deepDiffing : propKey === 'style' ? 1 : 0;
|
|
22
|
+
if (depth > 0) {
|
|
23
|
+
prop = diffProperties(lastProps[propKey], null, depth - 1);
|
|
24
|
+
if (!prop)
|
|
25
|
+
continue;
|
|
26
|
+
}
|
|
27
|
+
// For all other deleted properties we add it to the queue. We use
|
|
28
|
+
// the whitelist in the commit phase instead.
|
|
29
|
+
(updatePayload = updatePayload || {})[propKey] = prop;
|
|
23
30
|
}
|
|
24
|
-
// For all other deleted properties we add it to the queue. We use
|
|
25
|
-
// the whitelist in the commit phase instead.
|
|
26
|
-
(updatePayload = updatePayload || {})[propKey] = prop;
|
|
27
31
|
}
|
|
28
32
|
for (propKey in nextProps) {
|
|
33
|
+
// This loop is for finding difference between current properties and previous properties
|
|
29
34
|
var nextProp = nextProps[propKey];
|
|
30
35
|
var lastProp = lastProps != null ? lastProps[propKey] : undefined;
|
|
31
36
|
if (!nextProps.hasOwnProperty(propKey)
|
|
@@ -34,12 +39,33 @@ export function diffProperties(lastProps, nextProps, deepDiffing) {
|
|
|
34
39
|
continue;
|
|
35
40
|
}
|
|
36
41
|
var prop = nextProp;
|
|
37
|
-
if (propKey === 'style'
|
|
38
|
-
|
|
42
|
+
if (propKey === 'style') {
|
|
43
|
+
var prevWasString = (typeof lastProp === 'string');
|
|
44
|
+
var curIsString = (typeof prop === 'string');
|
|
45
|
+
if (prevWasString !== curIsString) {
|
|
46
|
+
(updatePayload = updatePayload || {})[styleStringSymbol] = typeof prop === 'string' ? prop : null;
|
|
47
|
+
if (curIsString) {
|
|
48
|
+
// Current style is string while previous is object, so revert all changes from the previous one
|
|
49
|
+
prop = diffProperties(lastProp, {}, 0);
|
|
50
|
+
if (!prop)
|
|
51
|
+
continue;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
else {
|
|
55
|
+
if (curIsString) {
|
|
56
|
+
// Both styles are string, style does not need changing
|
|
57
|
+
continue;
|
|
58
|
+
}
|
|
59
|
+
else {
|
|
60
|
+
// Both styles are object, take the difference
|
|
61
|
+
prop = diffProperties(lastProp, nextProp, 0);
|
|
62
|
+
if (!prop)
|
|
63
|
+
continue;
|
|
64
|
+
}
|
|
65
|
+
}
|
|
39
66
|
}
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
prop = diffProperties(lastProp, nextProp, depth - 1);
|
|
67
|
+
if (deepDiffing > 0) {
|
|
68
|
+
prop = diffProperties(lastProp, nextProp, deepDiffing - 1);
|
|
43
69
|
if (!prop)
|
|
44
70
|
continue;
|
|
45
71
|
}
|
|
@@ -1,12 +1,20 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
2
|
import { NativeContainerInstance } from '../models/renderer';
|
|
3
|
+
import { ObjectsRepo } from './async/objects';
|
|
4
|
+
import { AsyncNativeInstance } from './async/types';
|
|
3
5
|
interface RenderOptions {
|
|
4
6
|
hostContainer?: NativeContainerInstance;
|
|
5
7
|
disableHelpers?: boolean;
|
|
6
8
|
mode?: 'legacy' | 'concurrent';
|
|
9
|
+
sync?: boolean;
|
|
7
10
|
}
|
|
8
11
|
export declare const Renderer: {
|
|
9
|
-
render(element: React.ReactNode, options?: RenderOptions):
|
|
12
|
+
render(element: React.ReactNode, options?: RenderOptions): import("react-reconciler").Reconciler<import("./async/types").AsyncHostContext & {
|
|
13
|
+
refId: number;
|
|
14
|
+
} & {
|
|
15
|
+
component: import("../..").ReactUnity.IReactComponent;
|
|
16
|
+
fiberCache: ObjectsRepo<any>;
|
|
17
|
+
}, AsyncNativeInstance, AsyncNativeInstance, AsyncNativeInstance, import("../..").ReactUnity.IReactComponent> | import("react-reconciler").Reconciler<import("../..").ReactUnity.IReactComponent, import("../..").ReactUnity.IReactComponent, import("../..").ReactUnity.ITextComponent, import("../..").ReactUnity.IReactComponent, any>;
|
|
10
18
|
};
|
|
11
19
|
export declare const batchedUpdates: <A, R>(fn: (a: A) => R, a: A) => R;
|
|
12
20
|
export declare const flushSync: <A, R>(fn: (a: A) => R, a: A) => R;
|