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

Unable to invoke focus on touchable ref #160

Closed
ivodaveiga opened this issue Feb 9, 2021 · 3 comments
Closed

Unable to invoke focus on touchable ref #160

ivodaveiga opened this issue Feb 9, 2021 · 3 comments

Comments

@ivodaveiga
Copy link

Description

The focus() function throws an error (No command found with name "focus") when invoked on a touchable ref.
Tested on "Apple TV" simulator.

Screenshot 2021-02-09 at 11 40 39

React Native version:

System:
    OS: macOS 11.2
    CPU: (8) x64 Intel(R) Core(TM) i5-8257U CPU @ 1.40GHz
    Memory: 498.71 MB / 16.00 GB
    Shell: 5.8 - /bin/zsh
  Binaries:
    Node: 12.19.0 - /usr/local/bin/node
    Yarn: 1.22.10 - /usr/local/bin/yarn
    npm: 7.0.3 - /usr/local/bin/npm
    Watchman: 4.9.0 - /usr/local/bin/watchman
  Managers:
    CocoaPods: 1.10.0 - /usr/local/bin/pod
  SDKs:
    iOS SDK:
      Platforms: iOS 14.4, DriverKit 20.2, macOS 11.1, tvOS 14.3, watchOS 7.2
    Android SDK: Not Found
  IDEs:
    Android Studio: Not Found
    Xcode: 12.4/12D4e - /usr/bin/xcodebuild
  Languages:
    Java: Not Found
    Python: 2.7.16 - /usr/bin/python
  npmPackages:
    @react-native-community/cli: Not Found
    react: 16.13.1 => 16.13.1 
    react-native: Not Found
    react-native-macos: Not Found
    react-native-tvos:  0.63.4-0 
  npmGlobalPackages:
    *react-native*: Not Found

Steps To Reproduce

Use the reproducible demo below

  1. Press Button 1

Expected Results

Button 2is focused

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

https://github.com/ivodaveiga/react-native-tvos-focus-test

@douglowder
Copy link
Collaborator

The Touchable components do not have a focus() method -- that is a TextInput method. If you want to programmatically change focus, you should set the hasTVPreferredFocus prop on the component you want to focus.

@ivodaveiga
Copy link
Author

Thanks. Shouldn't that be reflected in typescript as it identifies the focus() function as a valid function inherited from the interface NativeMethods?
(I've updated the example repository to use typescript)

@douglowder
Copy link
Collaborator

@ivodaveiga I do see that the focus() method is there in the types -- maybe that is a bug in in @types/react-native. Checking the official docs at https://reactnative.dev, it does not appear that the method exists in any core components except TextInput.

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

No branches or pull requests

2 participants