Skip to content

Commit f8ffd4b

Browse files
authored
Modify template to use react-native-tvos for TV support (#1)
* Changes to align with react-native-tvos * Add TV specific code to example app * Update README * Update README and package.json
1 parent 2af035f commit f8ffd4b

File tree

6 files changed

+280
-34
lines changed

6 files changed

+280
-34
lines changed

README.md

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,31 +22,29 @@
2222
- Elegant usage directly within the [React Native CLI](https://github.com/react-native-community/cli)
2323
- Consistent with the default React Native template
2424
- Minimal additional dependencies
25+
- Support for Apple TV and Android TV using the [React Native for TV](https://github.com/react-native-tvos/react-native-tvos) package
2526

2627
## :arrow_forward: Usage
2728

2829
```sh
29-
npx react-native init MyApp --template react-native-template-typescript
30+
npx react-native init MyApp --template react-native-template-typescript-tv
3031
```
3132

3233
### Usage with older versions of React Native
3334

34-
#### e.g. `react-native@0.62.x`
35+
#### e.g. `react-native-tvos@0.63.1-3` (previous versions do not have TS types for TV props)
3536

3637
```sh
37-
npx react-native init MyApp --template react-native-template-typescript@6.4.*
38+
npx react-native init MyApp --template react-native-template-typescript-tv@6.5.8
3839
```
3940

4041
See the below table to find out which version of the template to use.
4142

42-
#### React Native <=> Template Version
43+
#### react-native-tvos Version <=> Template Version
4344

4445
| React Native | Template |
4546
|--- |--- |
46-
| 0.63 | 6.5.* |
47-
| 0.62 | 6.4.* |
48-
| 0.61 | 6.3.* |
49-
| 0.60 | 6.2.* |
47+
| 0.63.1-3 | 6.5.8 |
5048

5149
### Note on the legacy CLI
5250
There seems to be quite some confusion about the legacy CLI. This template only works with the new CLI. Make sure you have uninstalled the legacy `react-native-cli` first (`npm uninstall -g react-native-cli`), for the below command to work. If you wish to not use `npx`, you can also install the new CLI globally (`npm i -g @react-native-community/cli` or `yarn global add @react-native-community/cli`).

package.json

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
2-
"name": "react-native-template-typescript",
2+
"name": "react-native-template-typescript-tv",
33
"version": "0.0.1",
4-
"description": "Clean and minimalist React Native template for a quick start with TypeScript.",
4+
"description": "Clean and minimalist React Native template for a quick start with TypeScript for Android TV and Apple TV.",
55
"scripts": {
66
"prepublishOnly": "npm --no-git-tag-version version $TRAVIS_TAG"
77
},
@@ -11,7 +11,7 @@
1111
],
1212
"repository": {
1313
"type": "git",
14-
"url": "git+https://github.com/emin93/react-native-template-typescript.git"
14+
"url": "git+https://github.com/react-native-tvos/react-native-template-typescript-tv.git"
1515
},
1616
"keywords": [
1717
"react-native",
@@ -20,10 +20,10 @@
2020
"template",
2121
"boilerplate"
2222
],
23-
"author": "Emin Khateeb <[email protected]>",
23+
"author": "Emin Khateeb <[email protected]>, with TV modifications by Doug Lowder <[email protected]>",
2424
"license": "MIT",
2525
"bugs": {
26-
"url": "https://github.com/emin93/react-native-template-typescript/issues"
26+
"url": "https://github.com/react-native-tvos/react-native-template-typescript-tv/issues"
2727
},
28-
"homepage": "https://github.com/emin93/react-native-template-typescript#readme"
28+
"homepage": "https://github.com/react-native-tvos/react-native-template-typescript-tv#readme"
2929
}

template/App.tsx

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@ import {
1515
ScrollView,
1616
View,
1717
Text,
18-
StatusBar,
18+
useTVEventHandler,
19+
HWFocusEvent,
1920
} from 'react-native';
2021

2122
import {
@@ -26,28 +27,35 @@ import {
2627
ReloadInstructions,
2728
} from 'react-native/Libraries/NewAppScreen';
2829

30+
import 'react-native/tvos-types.d';
31+
2932
declare const global: {HermesInternal: null | {}};
3033

3134
const App = () => {
35+
const [lastEventType, setLastEventType] = React.useState('');
36+
const myTVEventHandler = (evt: HWFocusEvent) => {
37+
setLastEventType(evt.eventType);
38+
};
39+
useTVEventHandler(myTVEventHandler);
3240
return (
3341
<>
34-
<StatusBar barStyle="dark-content" />
3542
<SafeAreaView>
3643
<ScrollView
3744
contentInsetAdjustmentBehavior="automatic"
3845
style={styles.scrollView}>
3946
<Header />
40-
{global.HermesInternal == null ? null : (
41-
<View style={styles.engine}>
47+
<View style={styles.engine}>
48+
<Text style={styles.footer}>TVEvent: {lastEventType}</Text>
49+
{global.HermesInternal == null ? null : (
4250
<Text style={styles.footer}>Engine: Hermes</Text>
43-
</View>
44-
)}
51+
)}
52+
</View>
4553
<View style={styles.body}>
4654
<View style={styles.sectionContainer}>
4755
<Text style={styles.sectionTitle}>Step One</Text>
4856
<Text style={styles.sectionDescription}>
49-
Edit <Text style={styles.highlight}>App.tsx</Text> to change this
50-
screen and then come back to see your edits.
57+
Edit <Text style={styles.highlight}>App.tsx</Text> to change
58+
this screen and then come back to see your edits.
5159
</Text>
5260
</View>
5361
<View style={styles.sectionContainer}>

0 commit comments

Comments
 (0)