Files
react-native/ReactAndroid
Joshua Gross d7447fadeb Core React/Litho support and Java codegen
Summary:
Core React/Litho support and Java codegen. View updating still in progress.

Generated ViewManager code:

```
// Copyright 2004-present Facebook. All Rights Reserved.
//
// Autogenerated by ComponentsReactNativeSupportProcessor
package com.facebook.catalyst.samples.componentsembedding;

import com.facebook.litho.Component;
import com.facebook.litho.ComponentContext;
import com.facebook.litho.reactnative.ComponentsShadowNode;
import com.facebook.litho.reactnative.ComponentsViewManager;
import com.facebook.litho.reactnative.ReactLithoView;
import com.facebook.react.bridge.ReactApplicationContext;
import com.facebook.react.module.annotations.ReactModule;
import com.facebook.react.uimanager.ReactStylesDiffMap;
import com.facebook.react.uimanager.StateWrapper;
import com.facebook.react.uimanager.ThemedReactContext;
import java.util.HashMap;
import java.util.Map;

ReactModule(
    name = "SampleComponent"
)
public class GeneratedSampleComponentViewManager extends ComponentsViewManager {
  Override
  public String getName() {
    return "SampleComponent";
  }

  Override
  public ReactLithoView createViewInstanceWithProps(ThemedReactContext context,
      ReactStylesDiffMap props) {
    Map<String, Object> propsMap;
    if (props != null && props.toMap() != null) {
      propsMap = props.toMap();
    } else {
      // Non-Fabric will always follow this path, initial props are never provided;
      return ReactLithoView.create(context, null, null);
    }
    Component component = createComponentInstanceWithPropsMap(new ComponentContext(context), propsMap);
    return ReactLithoView.create(context, component, propsMap);
  }

  Override
  public Component createComponentInstanceWithPropsMap(ComponentContext context,
      Map<String, Object> propsMap) {
    SampleComponent.Builder componentBuilder = SampleComponent.create(context);
    setComponentBuilderPropsWithMap(componentBuilder, propsMap);
    return componentBuilder.build();
  }

  Override
  public void updateProperties(ReactLithoView view, ReactStylesDiffMap props) {
    super.updateProperties(view, props);
    Map<String, Object> propsMap = props.toMap();
    Map<String, Object> oldProps = view.getProps();
    if (oldProps == null) {
      // Non-Fabric RN will always terminate here; we do not store props, nor do we need to.;
      // Prop updating happens incrementally in non-Fabric RN.;
      return;
    }
    Map<String, Object> mergedProps = new HashMap<>(oldProps);
    mergedProps.putAll(propsMap);
    SampleComponent.Builder componentBuilder = SampleComponent.create(new ComponentContext(view.getComponentContext()));
    setComponentBuilderPropsWithMap(componentBuilder, mergedProps);
    view.setProps(mergedProps);
    view.setComponent(componentBuilder.build());
  }

  private void setComponentBuilderPropsWithMap(SampleComponent.Builder componentBuilder,
      Map<String, Object> propsMap) {
    if (propsMap != null && propsMap.containsKey("title")) {
      componentBuilder.title((((String)propsMap.getOrDefault("title", null))));
    }
    if (propsMap != null && propsMap.containsKey("imageUri")) {
      componentBuilder.imageUri(android.net.Uri.parse(((String)propsMap.getOrDefault("imageUri", null))));
    }
  }

  Override
  public GeneratedSampleComponentShadowNode createShadowNodeInstance(ReactApplicationContext context) {
    return new GeneratedSampleComponentShadowNode();
  }

  Override
  public Class<? extends ComponentsShadowNode> getShadowNodeClass() {
    return GeneratedSampleComponentShadowNode.class;
  }

  Override
  public void updateState(ReactLithoView view, StateWrapper stateWrapper) {
    view.setStateWrapper(stateWrapper);
  }
}
```

Reviewed By: shergin

Differential Revision: D14846423

fbshipit-source-id: 4eeeb991f7e32c0cec5e9307d6175b81c8fd034e
2019-05-08 14:53:51 -07:00
..
2018-05-27 15:17:55 -07:00

Building React Native for Android

See the docs on the website.

Running tests

When you submit a pull request CircleCI will automatically run all tests. To run tests locally, see Testing.