Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Android] createShadowNodeInstance function is not called #34416

Closed
troZee opened this issue Aug 15, 2022 · 5 comments
Closed

[Android] createShadowNodeInstance function is not called #34416

troZee opened this issue Aug 15, 2022 · 5 comments
Labels
Needs: Triage 🔍 Platform: Android Android applications. Type: New Architecture Issues and PRs related to new architecture (Fabric/Turbo Modules)

Comments

@troZee
Copy link
Contributor

troZee commented Aug 15, 2022

Description

In my library, I would like to update native parent view (probably it is called HostView), when react native child dimensions changed. I implemented it using onLayoutChange method but I would like to do it in synchronous manner. I just wanted to use shadow nodes for it, but for some reason it does not work, when fabric is enabled.

I checked all versions of RN from 68 and this issue occurs on all of them

Versions

68,69,70

Output of npx react-native info

System:
OS: macOS 12.1
CPU: (10) arm64 Apple M1 Pro
Memory: 128.70 MB / 32.00 GB
Shell: 5.8 - /bin/zsh
Binaries:
Node: 16.16.0 - ~/.nvm/versions/node/v16.16.0/bin/node
Yarn: 1.22.19 - ~/.nvm/versions/node/v16.16.0/bin/yarn
npm: 8.11.0 - ~/.nvm/versions/node/v16.16.0/bin/npm
Watchman: Not Found
Managers:
CocoaPods: 1.11.2 - /opt/homebrew/bin/pod
SDKs:
iOS SDK:
Platforms: DriverKit 21.2, iOS 15.2, macOS 12.1, tvOS 15.2, watchOS 8.3
Android SDK:
Android NDK: 24.0.8215888
IDEs:
Android Studio: 2021.2 AI-212.5712.43.2112.8815526
Xcode: 13.2.1/13C100 - /usr/bin/xcodebuild
Languages:
Java: 11.0.15 - sdkman/candidates/java/current/bin/javac
npmPackages:
@react-native-community/cli: Not Found
react: Not Found
react-native: Not Found
react-native-macos: Not Found
npmGlobalPackages:

Steps to reproduce

Apply below diff into RNTester

diff --git a/packages/rn-tester/android/app/src/main/java/com/facebook/react/uiapp/component/MyNativeViewManager.java b/packages/rn-tester/android/app/src/main/java/com/facebook/react/uiapp/component/MyNativeViewManager.java
index d8c8b731acb..d4de933f629 100644
--- a/packages/rn-tester/android/app/src/main/java/com/facebook/react/uiapp/component/MyNativeViewManager.java
+++ b/packages/rn-tester/android/app/src/main/java/com/facebook/react/uiapp/component/MyNativeViewManager.java
@@ -8,6 +8,8 @@
 package com.facebook.react.uiapp.component;
 
 import android.graphics.Color;
+import android.util.Log;
+
 import androidx.annotation.NonNull;
 import androidx.annotation.Nullable;
 import com.facebook.react.bridge.ReadableArray;
@@ -19,6 +21,11 @@ import com.facebook.react.uimanager.ViewProps;
 import com.facebook.react.uimanager.annotations.ReactProp;
 import com.facebook.react.viewmanagers.RNTMyNativeViewManagerDelegate;
 import com.facebook.react.viewmanagers.RNTMyNativeViewManagerInterface;
+import com.facebook.react.uimanager.LayoutShadowNode;
+import com.facebook.yoga.YogaMeasureFunction;
+import com.facebook.yoga.YogaMeasureMode;
+import com.facebook.yoga.YogaMeasureOutput;
+import com.facebook.yoga.YogaNode;
 
 /** View manager for {@link MyNativeView} components. */
 @ReactModule(name = MyNativeViewManager.REACT_CLASS)
@@ -27,6 +34,25 @@ public class MyNativeViewManager extends SimpleViewManager<MyNativeView>
 
   public static final String REACT_CLASS = "RNTMyNativeView";
 
+  public static class ExampleShadowNode extends LayoutShadowNode implements
+    YogaMeasureFunction {
+
+    public ExampleShadowNode() {
+      Log.d("", "ExampleShadowNode: ");
+    }
+    @Override
+    public long measure(
+      YogaNode node,
+      float width,
+      YogaMeasureMode widthMode,
+      float height,
+      YogaMeasureMode heightMode) {
+
+      return YogaMeasureOutput.make(width, height);
+    }
+
+  }
+
   private final ViewManagerDelegate<MyNativeView> mDelegate;
 
   public MyNativeViewManager() {
@@ -51,6 +77,16 @@ public class MyNativeViewManager extends SimpleViewManager<MyNativeView>
     return new MyNativeView(reactContext);
   }
 
+  @Override
+  public LayoutShadowNode createShadowNodeInstance() {
+    return new ExampleShadowNode();
+  }
+
+  @Override
+  public Class getShadowNodeClass() {
+    return ExampleShadowNode.class;
+  }
+
   @Override
   public void receiveCommand(
       @NonNull MyNativeView view, String commandName, @Nullable ReadableArray args) {

Current State:

ExampleShadowNode is not called

Expected State:

ExampleShadowNode should have been called

Snack, code example, screenshot, or link to a repository

callstack/react-native-slider#410

@troZee troZee added Needs: Triage 🔍 Type: New Architecture Issues and PRs related to new architecture (Fabric/Turbo Modules) labels Aug 15, 2022
@react-native-bot react-native-bot added the Platform: Android Android applications. label Aug 15, 2022
@cortinico
Copy link
Contributor

Is this related to New Architecture in any form @troZee ?

@troZee
Copy link
Contributor Author

troZee commented Aug 16, 2022

Is this related to New Architecture in any form @troZee ?

Yes, I would like to update HostView dimensions based on ReactNative Child in synchronous manner. I would expect this code to be called. Is this expectation incorrect somehow? @cortinico

@cortinico
Copy link
Contributor

Yes, I would like to update HostView dimensions based on ReactNative Child in synchronous manner. I would expect this code to be called. Is this expectation incorrect somehow? @cortinico

Sorry I overlooked your issue description and you mentioned "when fabric is enabled" which I missed. I was aksing as sometimes we have users click on "New Architecture" issues while in reality they're not.

I would suggest we move this to https://github.com/reactwg/react-native-new-architecture for now. You can apply with the link in the README if you don't have access.

@troZee
Copy link
Contributor Author

troZee commented Aug 16, 2022

This issue has been moved here: reactwg/react-native-new-architecture#70

@troZee troZee closed this as completed Aug 16, 2022
@NikiLee2016
Copy link

This issue has been moved here: reactwg/react-native-new-architecture#70

Hello, Did you find a solution for this? Cause I just met the same problme, I want to get RN views measurements synchronously

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Needs: Triage 🔍 Platform: Android Android applications. Type: New Architecture Issues and PRs related to new architecture (Fabric/Turbo Modules)
Projects
None yet
Development

No branches or pull requests

4 participants