@@ -22,7 +22,7 @@ import * as ReactNativeViewConfigRegistry from 'ReactNativeViewConfigRegistry';
2222import ReactFiberReconciler from 'react-reconciler' ;
2323
2424import deepFreezeAndThrowOnMutationInDev from 'deepFreezeAndThrowOnMutationInDev' ;
25- import emptyObject from 'fbjs/lib/emptyObject ' ;
25+ import invariant from 'fbjs/lib/invariant ' ;
2626
2727// Modules provided by RN:
2828import TextInputState from 'TextInputState' ;
@@ -35,6 +35,10 @@ import UIManager from 'UIManager';
3535// This means that they never overlap.
3636let nextReactTag = 2 ;
3737
38+ type HostContext = $ReadOnly < { |
39+ isInAParentText : boolean ,
40+ | } > ;
41+
3842/**
3943 * This is used for refs on host components.
4044 */
@@ -135,7 +139,7 @@ const ReactFabricRenderer = ReactFiberReconciler({
135139 type : string ,
136140 props : Props ,
137141 rootContainerInstance : Container ,
138- hostContext : { } ,
142+ hostContext : HostContext ,
139143 internalInstanceHandle : Object ,
140144 ) : Instance {
141145 const tag = nextReactTag ;
@@ -151,6 +155,11 @@ const ReactFabricRenderer = ReactFiberReconciler({
151155 }
152156 }
153157
158+ invariant (
159+ type !== 'RCTView' || ! hostContext . isInAParentText ,
160+ 'Nesting of <View> within <Text> is not currently supported.' ,
161+ ) ;
162+
154163 const updatePayload = ReactNativeAttributePayload . create (
155164 props ,
156165 viewConfig . validAttributes ,
@@ -175,9 +184,14 @@ const ReactFabricRenderer = ReactFiberReconciler({
175184 createTextInstance (
176185 text : string ,
177186 rootContainerInstance : Container ,
178- hostContext : { } ,
187+ hostContext : HostContext ,
179188 internalInstanceHandle : Object ,
180189 ) : TextInstance {
190+ invariant (
191+ hostContext . isInAParentText ,
192+ 'Text strings must be rendered within a <Text> component.' ,
193+ ) ;
194+
181195 const tag = nextReactTag ;
182196 nextReactTag += 2 ;
183197
@@ -203,12 +217,27 @@ const ReactFabricRenderer = ReactFiberReconciler({
203217 return false ;
204218 } ,
205219
206- getRootHostContext ( ) : { } {
207- return emptyObject ;
220+ getRootHostContext ( rootContainerInstance : Container ) : HostContext {
221+ return { isInAParentText : false } ;
208222 } ,
209223
210- getChildHostContext ( ) : { } {
211- return emptyObject ;
224+ getChildHostContext (
225+ parentHostContext : HostContext ,
226+ type : string ,
227+ ) : HostContext {
228+ const prevIsInAParentText = parentHostContext . isInAParentText ;
229+ const isInAParentText =
230+ type === 'AndroidTextInput' || // Android
231+ type === 'RCTMultilineTextInputView' || // iOS
232+ type === 'RCTSinglelineTextInputView' || // iOS
233+ type === 'RCTText' ||
234+ type === 'RCTVirtualText' ;
235+
236+ if ( prevIsInAParentText !== isInAParentText ) {
237+ return { isInAParentText} ;
238+ } else {
239+ return parentHostContext ;
240+ }
212241 } ,
213242
214243 getPublicInstance ( instance ) {
@@ -230,7 +259,7 @@ const ReactFabricRenderer = ReactFiberReconciler({
230259 oldProps : Props ,
231260 newProps : Props ,
232261 rootContainerInstance : Container ,
233- hostContext : { } ,
262+ hostContext : HostContext ,
234263 ) : null | Object {
235264 const viewConfig = instance . canonical . viewConfig ;
236265 const updatePayload = ReactNativeAttributePayload . diff (
0 commit comments