@@ -2,6 +2,7 @@ import React from 'react'
22import invariant from 'invariant'
33import ReactFiberReconciler from 'react-reconciler'
44import { DefaultEventPriority } from 'react-reconciler/constants'
5+ import { unstable_now as now } from 'scheduler'
56import { emptyObject } from './utils'
67import Gradient from './Gradient'
78import Text from './Text'
@@ -50,38 +51,12 @@ const freeComponentAndChildren = (c) => {
5051 freeComponentToPool ( c )
5152}
5253
54+ /** @type {ReactFiberReconciler.HostConfig } */
5355const CanvasHostConfig = {
54- supportsHydration : false ,
55- supportsPersistence : true ,
56- cancelTimeout : clearTimeout ,
57- scheduleTimeout : setTimeout ,
58- noTimeout : - 1 ,
59- detachDeletedInstance ( ) { } ,
60- getInstanceFromScope ( ) {
61- return null
62- } ,
63- preparePortalMount ( ) { } ,
64- afterActiveInstanceBlur ( ) { } ,
65- beforeActiveInstanceBlur ( ) { } ,
66- getCurrentEventPriority ( ) {
67- return DefaultEventPriority
68- } ,
69- getInstanceFromNode ( ) {
70- return undefined
71- } ,
72- prepareScopeUpdate ( ) { } ,
73- clearContainer ( ) { } ,
74- appendInitialChild ( parentInstance , child ) {
75- if ( typeof child === 'string' ) {
76- // Noop for string children of Text (eg <Text>{'foo'}{'bar'}</Text>)
77- invariant ( false , 'Text children should already be flattened.' )
78- return
79- }
80-
81- child . getLayer ( ) . inject ( parentInstance . getLayer ( ) )
82- } ,
56+ supportsMutation : true ,
57+ supportsPersistence : false ,
8358
84- createInstance ( type , props /* , internalInstanceHandle */ ) {
59+ createInstance ( type , props ) {
8560 let instance
8661
8762 const pool = componentPool [ type ]
@@ -100,34 +75,32 @@ const CanvasHostConfig = {
10075 return instance
10176 } ,
10277
103- createTextInstance (
104- text /* , rootContainerInstance, internalInstanceHandle */
105- ) {
78+ createTextInstance ( text ) {
10679 return text
10780 } ,
10881
109- finalizeInitialChildren ( /* domElement, type, props */ ) {
110- return false
111- } ,
82+ appendInitialChild ( parentInstance , child ) {
83+ if ( typeof child === 'string' ) {
84+ // Noop for string children of Text (eg <Text>{'foo'}{'bar'}</Text>)
85+ invariant ( false , 'Text children should already be flattened.' )
86+ return
87+ }
11288
113- getPublicInstance ( instance ) {
114- return instance
89+ child . getLayer ( ) . inject ( parentInstance . getLayer ( ) )
11590 } ,
11691
117- prepareForCommit ( ) {
118- return null
92+ finalizeInitialChildren ( ) {
93+ return false
11994 } ,
12095
121- prepareUpdate ( /* domElement, type, oldProps, newProps */ ) {
96+ prepareUpdate ( ) {
12297 return UPDATE_SIGNAL
12398 } ,
12499
125- resetAfterCommit ( ) {
126- // Noop
127- } ,
128-
129- shouldDeprioritizeSubtree ( /* type, props */ ) {
130- return false
100+ shouldSetTextContent ( type , props ) {
101+ return (
102+ typeof props . children === 'string' || typeof props . children === 'number'
103+ )
131104 } ,
132105
133106 getRootHostContext ( ) {
@@ -138,15 +111,31 @@ const CanvasHostConfig = {
138111 return emptyObject
139112 } ,
140113
141- shouldSetTextContent ( type , props ) {
142- return (
143- typeof props . children === 'string' || typeof props . children === 'number'
144- )
114+ getPublicInstance ( instance ) {
115+ return instance
145116 } ,
146117
147- isPrimaryRenderer : false ,
118+ prepareForCommit ( ) {
119+ return null
120+ } ,
148121
149- supportsMutation : true ,
122+ resetAfterCommit ( ) {
123+ // Noop
124+ } ,
125+
126+ preparePortalMount ( ) { } ,
127+
128+ now,
129+
130+ scheduleTimeout : setTimeout ,
131+
132+ cancelTimeout : clearTimeout ,
133+
134+ noTimeout : - 1 ,
135+
136+ queueMicrotask,
137+
138+ isPrimaryRenderer : false ,
150139
151140 appendChild ( parentInstance , child ) {
152141 const childLayer = child . getLayer ( )
@@ -161,6 +150,26 @@ const CanvasHostConfig = {
161150 parentLayer . invalidateLayout ( )
162151 } ,
163152
153+ getCurrentEventPriority ( ) {
154+ return DefaultEventPriority
155+ } ,
156+
157+ getInstanceFromNode ( ) {
158+ return undefined
159+ } ,
160+
161+ beforeActiveInstanceBlur ( ) { } ,
162+
163+ afterActiveInstanceBlur ( ) { } ,
164+
165+ prepareScopeUpdate ( ) { } ,
166+
167+ getInstanceFromScope ( ) {
168+ return null
169+ } ,
170+
171+ detachDeletedInstance ( ) { } ,
172+
164173 appendChildToContainer ( parentInstance , child ) {
165174 const childLayer = child . getLayer ( )
166175 const parentLayer = parentInstance . getLayer ( )
@@ -205,7 +214,11 @@ const CanvasHostConfig = {
205214 instance . applyLayerProps ( oldProps , newProps )
206215 instance . getLayer ( ) . invalidateLayout ( )
207216 }
208- }
217+ } ,
218+
219+ clearContainer ( ) { } ,
220+
221+ supportsHydration : false
209222}
210223
211224const CanvasRenderer = ReactFiberReconciler ( CanvasHostConfig )
0 commit comments