Pass State to preallocateView and createView methods whenever possible

Summary:
For some components, we will have state as soon as the ShadowNode is created that may be meaningful. In those cases, ViewManagers should be able to use State to create or preallocate views.

FB: This will be used in following diffs for Litho support.

Reviewed By: mdvacca

Differential Revision: D15343702

fbshipit-source-id: 8fd672251cb88dea662b5cae5a9efc96877d28a9
This commit is contained in:
Joshua Gross authored and Facebook Github Bot committed 2019-05-21 15:05:18 -07:00
1 parent c9df1db00a
commit b05761f1bb
12 files changed
+67 -41

No files matched your search

@@ -11,10 +11,8 @@ import android.content.Context;
import android.view.View;
import com.facebook.react.bridge.BaseJavaModule;
import com.facebook.react.bridge.ReactApplicationContext;
import com.facebook.react.bridge.ReactContext;
import com.facebook.react.bridge.ReadableArray;
import com.facebook.react.bridge.ReadableMap;
import com.facebook.react.uimanager.StateWrapper;
import com.facebook.react.touch.JSResponderHandler;
import com.facebook.react.touch.ReactInterceptingViewGroup;
import com.facebook.react.uimanager.annotations.ReactProp;
@@ -41,6 +39,7 @@ public abstract class ViewManager<T extends View, C extends ReactShadowNode>
*
* @param viewToUpdate
* @param props
* @param stateWrapper
*/
public void updateProperties(@Nonnull T viewToUpdate, ReactStylesDiffMap props) {
ViewManagerPropertyUpdater.updateProps(this, viewToUpdate, props);
@@ -53,17 +52,18 @@ public abstract class ViewManager<T extends View, C extends ReactShadowNode>
private final @Nonnull T createView(
@Nonnull ThemedReactContext reactContext,
JSResponderHandler jsResponderHandler) {
return this.createViewWithProps(reactContext, null, jsResponderHandler);
return createView(reactContext, null, null, jsResponderHandler);
}
/**
* Creates a view with knowledge of props.
*/
public @Nonnull T createViewWithProps(
public @Nonnull T createView(
@Nonnull ThemedReactContext reactContext,
ReactStylesDiffMap props,
@Nullable ReactStylesDiffMap props,
@Nullable StateWrapper stateWrapper,
JSResponderHandler jsResponderHandler) {
T view = createViewInstanceWithProps(reactContext, props);
T view = createViewInstance(reactContext, props, stateWrapper);
addEventEmitters(reactContext, view);
if (view instanceof ReactInterceptingViewGroup) {
((ReactInterceptingViewGroup) view).setOnInterceptTouchEventListener(jsResponderHandler);
@@ -115,7 +115,7 @@ public abstract class ViewManager<T extends View, C extends ReactShadowNode>
* Override it if you need props upon creation of the view.
* @param reactContext
*/
protected @Nonnull T createViewInstanceWithProps(@Nonnull ThemedReactContext reactContext, ReactStylesDiffMap initialProps) {
protected @Nonnull T createViewInstance(@Nonnull ThemedReactContext reactContext, @Nullable ReactStylesDiffMap initialProps, @Nullable StateWrapper stateWrapper) {
T view = createViewInstance(reactContext);
if (initialProps != null) {
updateProperties(view, initialProps);