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

Feat/make create rn compatible #111

Merged
merged 16 commits into from
Jun 27, 2023
Merged

Conversation

aurimasmi
Copy link
Contributor

@aurimasmi aurimasmi commented Jun 22, 2023

Tested this on latest react-native-tvos https://github.com/react-native-tvos/react-native-tvos

Steps how to test it:

  • Create blank react-native-tvos
  • Install flexn create 0.21.2-alpha.38 and required peer dependencies
  • In MainActivity.java add this snippet
  import io.flexn.create.TvRemoteHandlerModule;
  import android.view.KeyEvent;
  
  @Override
  public boolean onKeyUp(int keyCode, KeyEvent event) {
    TvRemoteHandlerModule.getInstance().onKeyEvent(event, "up");

    return super.onKeyUp(keyCode, event);
  }

   @Override
   public boolean onKeyLongPress(int keyCode, KeyEvent event) {
      TvRemoteHandlerModule.getInstance().onKeyEvent(event, "longPress");

      return super.onKeyLongPress(keyCode, event);
   }

   @Override
   public boolean onKeyDown(int keyCode, KeyEvent event) {
      if (keyCode == KeyEvent.KEYCODE_DPAD_RIGHT || keyCode == KeyEvent.KEYCODE_DPAD_LEFT || keyCode == KeyEvent.KEYCODE_DPAD_UP || keyCode == KeyEvent.KEYCODE_DPAD_DOWN) {
        event.startTracking();
        TvRemoteHandlerModule.getInstance().onKeyEvent(event, "down");
        
        return true;
      }

      TvRemoteHandlerModule.getInstance().onKeyEvent(event, "down");
      return super.onKeyDown(keyCode, event);
   }
  • You can add test code as simple as that
import React from 'react';
import {Text} from 'react-native';
import {
  App as CreateApp,
  Pressable,
  Screen,
  View,
  Debugger as CreateDebugger,
} from '@flexn/create';

function Content() {
  return (
    <Screen>
      <View>
        <Pressable
          onFocus={() => {
            console.log('focus...');
          }}>
          <Text>Hello from button</Text>
        </Pressable>
        <Pressable>
          <Text>Hello from button</Text>
        </Pressable>
        <Pressable>
          <Text>Hello from button</Text>
        </Pressable>
      </View>
    </Screen>
  );
}

function App(): JSX.Element {
  return (
    <CreateApp style={{flex: 1}}>
      <Content />
      <CreateDebugger />
    </CreateApp>
  );
}
export default App;

@aurimasmi aurimasmi linked an issue Jun 22, 2023 that may be closed by this pull request
@aurimasmi aurimasmi marked this pull request as ready for review June 22, 2023 19:46
@aurimasmi aurimasmi added this to the 0.21 milestone Jun 26, 2023
@aurimasmi aurimasmi linked an issue Jun 26, 2023 that may be closed by this pull request
@mihaiblaga89
Copy link
Member

mihaiblaga89 commented Jun 26, 2023

@aurimasmi I also needed to install react-native-vector-icons as a dependency. However I can't run it on android. Snippet that you mentioned is added Android works after adding

import android.view.KeyEvent;

For tvos I get the error

Invariant Violation: requireNativeComponent: "TvFocusableView" was not found in the UIManager.

@pavjacko
Copy link
Member

@aurimasmi @mihaiblaga89 it would be good to merge latest main here

# Conflicts:
#	packages/app-harness/package.json
#	packages/create/package.json
#	packages/template-starter/package.json
@aurimasmi
Copy link
Contributor Author

@aurimasmi I also needed to install react-native-vector-icons as a dependency. However I can't run it on android. Snippet that you mentioned is added Android works after adding

import android.view.KeyEvent;

For tvos I get the error

Invariant Violation: requireNativeComponent: "TvFocusableView" was not found in the UIManager.

tvos fix version 0.21.2-alpha.39

I also don't like react-native-vector-icons being there it supports single component. Happy to remove it or hear more opinions

@aurimasmi aurimasmi merged commit 5df4e77 into main Jun 27, 2023
1 check failed
@aurimasmi aurimasmi deleted the feat/make-create-rn-compatible branch August 23, 2023 06:28
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

Successfully merging this pull request may close these issues.

Make create and focus manager react-native compatible onHoverIn missing from types in Pressable
3 participants