mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
Refactor creation of views in Fabric Android
Summary: This diff refactors the createViewInstance method in order to ensure that viewID is set before props are updated in the view. This is necessary because there are components that deliver events at the same time their props are set. This means that some components might not have their viewId set correctly when events are delivered. Since viewId is used to determine if a view belongs to Fabric or Paper, there are cases when the events are not delivered to the right renderer changelog: [internal] Reviewed By: JoshuaGross Differential Revision: D25667987 fbshipit-source-id: 4acfa8f80d66e9e59514354481957d7d3b571248
This commit is contained in:
committed by
Facebook GitHub Bot
parent
381fb395ad
commit
2e63147109
@@ -533,7 +533,7 @@ public class MountingManager {
|
||||
// View Managers are responsible for dealing with initial state and props.
|
||||
view =
|
||||
viewManager.createView(
|
||||
themedReactContext, propsDiffMap, stateWrapper, mJSResponderHandler);
|
||||
reactTag, themedReactContext, propsDiffMap, stateWrapper, mJSResponderHandler);
|
||||
view.setId(reactTag);
|
||||
}
|
||||
|
||||
|
||||
+1
-1
@@ -278,7 +278,7 @@ public class NativeViewHierarchyManager {
|
||||
try {
|
||||
ViewManager viewManager = mViewManagers.get(className);
|
||||
|
||||
View view = viewManager.createView(themedContext, null, null, mJSResponderHandler);
|
||||
View view = viewManager.createView(tag, themedContext, null, null, mJSResponderHandler);
|
||||
mTagsToViews.put(tag, view);
|
||||
mTagsToViewManagers.put(tag, viewManager);
|
||||
|
||||
|
||||
@@ -67,19 +67,14 @@ public abstract class ViewManager<T extends View, C extends ReactShadowNode>
|
||||
return null;
|
||||
}
|
||||
|
||||
/** Creates a view and installs event emitters on it. */
|
||||
private final @NonNull T createView(
|
||||
@NonNull ThemedReactContext reactContext, JSResponderHandler jsResponderHandler) {
|
||||
return createView(reactContext, null, null, jsResponderHandler);
|
||||
}
|
||||
|
||||
/** Creates a view with knowledge of props and state. */
|
||||
public @NonNull T createView(
|
||||
int reactTag,
|
||||
@NonNull ThemedReactContext reactContext,
|
||||
@Nullable ReactStylesDiffMap props,
|
||||
@Nullable StateWrapper stateWrapper,
|
||||
JSResponderHandler jsResponderHandler) {
|
||||
T view = createViewInstance(reactContext, props, stateWrapper);
|
||||
T view = createViewInstance(reactTag, reactContext, props, stateWrapper);
|
||||
if (view instanceof ReactInterceptingViewGroup) {
|
||||
((ReactInterceptingViewGroup) view).setOnInterceptTouchEventListener(jsResponderHandler);
|
||||
}
|
||||
@@ -129,13 +124,18 @@ public abstract class ViewManager<T extends View, C extends ReactShadowNode>
|
||||
* that will call createViewInstance for you. Override it if you need props upon creation of the
|
||||
* view.
|
||||
*
|
||||
* @param reactContext
|
||||
* @param reactTag reactTag that should be set as ID of the view instance
|
||||
* @param reactContext ReactContext used to initialize view instance
|
||||
* @param initialProps initial props for the view instance
|
||||
* @param stateWrapper initial state for the view instance
|
||||
*/
|
||||
protected @NonNull T createViewInstance(
|
||||
int reactTag,
|
||||
@NonNull ThemedReactContext reactContext,
|
||||
@Nullable ReactStylesDiffMap initialProps,
|
||||
@Nullable StateWrapper stateWrapper) {
|
||||
T view = createViewInstance(reactContext);
|
||||
view.setId(reactTag);
|
||||
addEventEmitters(reactContext, view);
|
||||
if (initialProps != null) {
|
||||
updateProperties(view, initialProps);
|
||||
|
||||
Reference in New Issue
Block a user