Más contenido relacionado La actualidad más candente (20) Similar a Native modules and ui components (20) Native modules and ui components13. コールバックで値を返却した理由
The return type of bridge methods is always void. React Native bridge is
asynchronous, so the only way to pass a result to JavaScript is by using callbacks or
emitting events (see below).
自作したNativeModuleから値を返却するには、
コールバックかイベント発行となる(iOS/Android)
イベントの発行について
https://facebook.github.io/react-native/docs/native-modules-
android#sending-events-to-javascript
18. Yoga
Facebookが公開しているクロスプラットフォームのレイアウトエンジン
github: https://github.com/facebook/yoga
document: https://yogalayout.com/docs
ReactNativeのレイアウトエンジンYogaの仕組み
前編: https://blog.engineer.adways.net/entry/2018/08/24/202254
後編: https://blog.engineer.adways.net/entry/2018/08/31/180000
続編: https://blog.engineer.adways.net/entry/2018/09/07/193000
19. LayoutShadowNodeの拡張
public class ShadowNode extends LayoutShadowNode implements YogaMeasureFunction {
public Integer viewTagToShadowNode = 0;
public ShadowNode() {
this.setMeasureFunction(this);
}
@Override
public long measure(
YogaNode node,
float width, YogaMeasureMode widthMode,
float height, YogaMeasureMode heightMode) {
int yogaWidth = 1080;
int yogaHeight = 607;
Integer viewWidth = viewToWidth.get(this.viewTagToShadowNode);
Integer viewHeight = viewToHeight.get(this.viewTagToShadowNode);
if (viewWidth != null && viewHeight != null) {
yogaWidth = viewWidth;
yogaHeight = viewHeight;
}
return YogaMeasureOutput.make(yogaWidth, yogaHeight);
}
}