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

Id not working on Touchable* #38117

Closed
ayush547 opened this issue Jun 28, 2023 · 3 comments
Closed

Id not working on Touchable* #38117

ayush547 opened this issue Jun 28, 2023 · 3 comments

Comments

@ayush547
Copy link

ayush547 commented Jun 28, 2023

Description

Id prop is replacing NativeID prop, but the PR #34522 that added these changes includes only TouchableWithoutFeedback.
Other Touchables like TouchableOpacity, TouchableHighlight etc all inherit from TouchableWithoutFeedback props, they should support Id prop too, but this is not present currently.

React Native Version

0.72.0

Output of npx react-native info

info Fetching system and libraries information...
System:
OS: Windows 10 10.0.22621
CPU: (8) x64 11th Gen Intel(R) Core(TM) i7-1185G7 @ 3.00GHz
Memory: 11.98 GB / 31.71 GB
Binaries:
Node:
version: 18.5.0
path: C:\Program Files\nodejs\node.EXE
Yarn:
version: 1.22.19
path: ~\AppData\Roaming\npm\yarn.CMD
npm:
version: 8.12.1
path: C:\Program Files\nodejs\npm.CMD
Watchman: Not Found
SDKs:
Android SDK: Not Found
Windows SDK:
AllowDevelopmentWithoutDevLicense: Enabled
AllowAllTrustedApps: Enabled
Versions:
- 10.0.19041.0
IDEs:
Android Studio: AI-212.5712.43.2112.8609683
Visual Studio:
- 16.11.33801.447 (Visual Studio Community 2019)
Languages:
Java: 11.0.15
Ruby: Not Found
npmPackages:
"@react-native-community/cli": Not Found
react:
installed: 18.2.0
wanted: 18.2.0
react-native:
installed: 0.72.0
wanted: 0.72.0
react-native-windows: Not Found
npmGlobalPackages:
"react-native": Not Found
Android:
hermesEnabled: true
newArchEnabled: false
iOS:
hermesEnabled: Not found
newArchEnabled: Not found

Steps to reproduce

Set Id prop on a touchableOpacity and try to access it using ReactFindViewUtil.findView(parentView, viewId). This fails.

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

TSX -

    <View>
      <TouchableOpacity
        onPress={onPress}
        id={id}
        accessibilityRole="button">
        <Text>Click to invoke your native module!</Text>
      </TouchableOpacity>
    </View>

Android Native Module -

   private View findView(String viewId) {
      activity = getCurrentActivity();
      if (activity == null) {
         Log.d("FocusModule", "Activity is null");
         return null;
      }
      View parentView = activity.getWindow().getDecorView().getRootView();
      if (parentView == null) {
         Log.d("FocusModule", "Parent view is null");
         return null;
      }
      return ReactFindViewUtil.findView(parentView, viewId);
   }

Verify Null is not returned.
Same code works while nativeID is set. But typescript complains that nativeID is not a supported prop.

@cortinico
Copy link
Contributor

@gabrieldonadel can you take a look at this one?

@gabrieldonadel
Copy link
Collaborator

Here you go @cortinico #38169

@ayush547
Copy link
Author

ayush547 commented Jul 4, 2023

@rohanprasadofficial FYI

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants