Giter Club home page Giter Club logo

nickavolpe / react-native-tvos Goto Github PK

View Code? Open in Web Editor NEW

This project forked from react-native-tvos/react-native-tvos

0.0 1.0 0.0 148.23 MB

React Native repo with additions for Apple TV support. https://dlowder-salesforce.github.io/react-native-apple-tv/

License: MIT License

JavaScript 49.55% Shell 0.38% Objective-C 11.60% Ruby 0.42% HTML 0.15% CSS 0.01% Objective-C++ 4.16% C 0.09% C++ 12.73% Python 1.49% Java 19.21% Assembly 0.09% IDL 0.02% Prolog 0.01% Makefile 0.09% Batchfile 0.01% CMake 0.01% Kotlin 0.01%

react-native-tvos's Introduction

react-native-tvos

Going forward, Apple TV support for React Native will be maintained here and in the corresponding react-native-tvos NPM package, and not in the core repo. This is a full fork of the main repository, with only the changes needed to support Apple TV.

Releases of react-native-tvos will be based on a public release of react-native; e.g. the 0.60.4-1 release of this package will be derived from the 0.60.4 release of react-native.

You will find the relevant tvOS support and maintence within the branches marked tvos;

To build your project for Apple TV, you should change your package.json imports to import react-native as follows, so that this package is used.

"react-native": "npm:[email protected]",

General support for Apple TV

TV devices support has been implemented with the intention of making existing React Native applications "just work" on Apple TV, with few or no changes needed in the JavaScript code for the applications.

The RNTester app supports Apple TV.

  • Without cocoapods: In RNTester/RNTester.xcodeproj, use the RNTester-tvOS build target to build for tvOS.
  • With cocoapods: In this repo, RNTester/Podfile and RNTester/RNTesterPods.xcodeproj have been modified to work for tvOS. Run pod install, then open RNTesterPods.xcworkspace and build.

Build changes

  • Native layer: React Native Xcode projects all now have Apple TV build targets, with names ending in the string '-tvOS'.

  • react-native init: New React Native projects created with react-native init will have Apple TV target automatically created in their XCode projects. To use this NPM package for creating a new project, you can reference it as in the following example:

react-native init TestApp --version=react-native@npm:[email protected]
  • JavaScript layer: Support for Apple TV has been added to Platform.ios.js. You can check whether code is running on AppleTV by doing
var Platform = require('Platform');
var running_on_tv = Platform.isTV;

// If you want to be more specific and only detect devices running tvOS
// (but no Android TV devices) you can use:
var running_on_apple_tv = Platform.isTVOS;

Code changes

  • General support for tvOS: Apple TV specific changes in native code are all wrapped by the TARGET_OS_TV define. These include changes to suppress APIs that are not supported on tvOS (e.g. web views, sliders, switches, status bar, etc.), and changes to support user input from the TV remote or keyboard.

  • Common codebase: Since tvOS and iOS share most Objective-C and JavaScript code in common, most documentation for iOS applies equally to tvOS.

  • Access to touchable controls: When running on Apple TV, the native view class is RCTTVView, which has additional methods to make use of the tvOS focus engine. The Touchable mixin has code added to detect focus changes and use existing methods to style the components properly and initiate the proper actions when the view is selected using the TV remote, so TouchableWithoutFeedback, TouchableHighlight and TouchableOpacity will "just work". In particular:

    • onFocus will be executed when the touchable view goes into focus
    • onBlur will be executed when the touchable view goes out of focus
    • onPress will be executed when the touchable view is actually selected by pressing the "select" button on the TV remote.
  • TV remote/keyboard input: A new native class, RCTTVRemoteHandler, sets up gesture recognizers for TV remote events. When TV remote events occur, this class fires notifications that are picked up by RCTTVNavigationEventEmitter (a subclass of RCTEventEmitter), that fires a JS event. This event will be picked up by instances of the TVEventHandler JavaScript object. Application code that needs to implement custom handling of TV remote events can create an instance of TVEventHandler and listen for these events, as in the following code:

var TVEventHandler = require('TVEventHandler');

class Game2048 extends React.Component {
  _tvEventHandler: any;

  _enableTVEventHandler() {
    this._tvEventHandler = new TVEventHandler();
    this._tvEventHandler.enable(this, function(cmp, evt) {
      if (evt && evt.eventType === 'right') {
        cmp.setState({board: cmp.state.board.move(2)});
      } else if(evt && evt.eventType === 'up') {
        cmp.setState({board: cmp.state.board.move(1)});
      } else if(evt && evt.eventType === 'left') {
        cmp.setState({board: cmp.state.board.move(0)});
      } else if(evt && evt.eventType === 'down') {
        cmp.setState({board: cmp.state.board.move(3)});
      } else if(evt && evt.eventType === 'playPause') {
        cmp.restartGame();
      }
    });
  }

  _disableTVEventHandler() {
    if (this._tvEventHandler) {
      this._tvEventHandler.disable();
      delete this._tvEventHandler;
    }
  }

  componentDidMount() {
    this._enableTVEventHandler();
  }

  componentWillUnmount() {
    this._disableTVEventHandler();
  }
  • Turbomodules: Working as of the 0.60.4-0 release.

  • Dev Menu support: On the simulator, cmd-D will bring up the developer menu, just like on iOS. To bring it up on a real Apple TV device, make a long press on the play/pause button on the remote. (Please do not shake the Apple TV device, that will not work :) )

  • TV remote animations: RCTTVView native code implements Apple-recommended parallax animations to help guide the eye as the user navigates through views. The animations can be disabled or adjusted with new optional view properties.

  • Back navigation with the TV remote menu button: The BackHandler component, originally written to support the Android back button, now also supports back navigation on the Apple TV using the menu button on the TV remote.

  • TabBarIOS behavior: The TabBarIOS component wraps the native UITabBar API, which works differently on Apple TV. To avoid jittery rerendering of the tab bar in tvOS (see this issue), the selected tab bar item can only be set from Javascript on initial render, and is controlled after that by the user through native code.

  • TVMenuControl: This module provides methods to enable and disable navigation using the menu key on the TV remote. This is required in order to fix an issue with Apple's guidelines for menu key navigation (see facebook/react-native#18930). The RNTester app uses this new module to implement correct menu key behavior.

  • TVFocusGuideView: This component provides support for Apple's UIFocusGuide API, to help ensure that focusable controls can be navigated to, even if they are not directly in line with other controls. A new example is provided in RNTester.

  • Known issues:

    • As of the 0.60.4-0 release, Fabric code compiles. Does not yet run in RNTester (Yoga errors) -- the issue is under investigation.

react-native-tvos's People

Contributors

shergin avatar javache avatar davidaurelio avatar sahrens avatar vjeux avatar hramos avatar nicklockwood avatar mdvacca avatar tadeuzagallo avatar frantic avatar fkgozali avatar thesavior avatar cpojer avatar janicduplessis avatar bestander avatar yungsters avatar ide avatar martinbigio avatar mkonicek avatar aaronechiu avatar astreet avatar rsnara avatar mhorowitz avatar andreicoman11 avatar ayc1 avatar rafeca avatar zhongwuzw avatar sophiebits avatar foghina avatar rickhanlonii avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.