mirror of
https://github.com/zhigang1992/react-native.git
synced 2026-01-12 22:50:10 +08:00
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
This commit is contained in:
committed by
Facebook Github Bot
parent
343f0a1d50
commit
d7447fadeb
@@ -7,6 +7,8 @@
|
||||
|
||||
package com.facebook.react.uimanager;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import android.view.View;
|
||||
@@ -41,6 +43,10 @@ public class ReactStylesDiffMap {
|
||||
mBackingMap = props;
|
||||
}
|
||||
|
||||
public Map<String, Object> toMap () {
|
||||
return mBackingMap.toHashMap();
|
||||
}
|
||||
|
||||
public boolean hasKey(String name) {
|
||||
return mBackingMap.hasKey(name);
|
||||
}
|
||||
|
||||
@@ -35,7 +35,14 @@ import javax.annotation.Nullable;
|
||||
public abstract class ViewManager<T extends View, C extends ReactShadowNode>
|
||||
extends BaseJavaModule {
|
||||
|
||||
public final void updateProperties(@Nonnull T viewToUpdate, ReactStylesDiffMap props) {
|
||||
/**
|
||||
* For the vast majority of ViewManagers, you will not need to override this. Only
|
||||
* override this if you really know what you're doing and have a very unique use-case.
|
||||
*
|
||||
* @param viewToUpdate
|
||||
* @param props
|
||||
*/
|
||||
public void updateProperties(@Nonnull T viewToUpdate, ReactStylesDiffMap props) {
|
||||
ViewManagerPropertyUpdater.updateProps(this, viewToUpdate, props);
|
||||
onAfterUpdateTransaction(viewToUpdate);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user