Skip to content

Commit 09a7f05

Browse files
committed
More styling and comments
1 parent 8e9b80b commit 09a7f05

File tree

1 file changed

+45
-14
lines changed

1 file changed

+45
-14
lines changed

App.js

Lines changed: 45 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,14 @@ import {createStackNavigator} from '@react-navigation/stack';
1818
/**
1919
* We use this Button component instead of the one from react-native,
2020
* because we need to pass in `isTVSelectable` and have more control
21-
* over styling.
21+
* over styling. We also use magnification instead of opacity to highlight
22+
* which button is focused.
2223
*/
2324
function Button({title, onPress, onFocus, isTVSelectable}) {
2425
return (
2526
<TouchableOpacity
27+
tvParallaxProperties={{magnification: 1.2}}
28+
activeOpacity={1.0}
2629
onPress={() => onPress()}
2730
onFocus={() => onFocus()}
2831
isTVSelectable={isTVSelectable}>
@@ -35,6 +38,38 @@ Button.defaultProps = {
3538
isTVSelectable: true,
3639
};
3740

41+
/**
42+
* Demo button for the upper right that doesn't do anything.
43+
* It is styled to invisibly extend close to the center of the screen,
44+
* so that it will be reachable by the tvOS focus engine without having
45+
* to implement a TVFocusGuideView. We use tint instead of magnification
46+
* or opacity to highlight this button when focused.
47+
*/
48+
function InfoButton() {
49+
const [infoButtonFocused, setInfoButtonFocused] = React.useState(false);
50+
return (
51+
<TouchableOpacity
52+
activeOpacity={1.0}
53+
style={styles.infoButtonContainer}
54+
onPress={() => alert('Info')} /* eslint-disable-line no-alert */
55+
onFocus={() => {
56+
console.log('Focus: Info button');
57+
setInfoButtonFocused(true);
58+
}}
59+
onBlur={() => setInfoButtonFocused(false)}>
60+
<View style={styles.spacer} />
61+
<Text
62+
style={
63+
infoButtonFocused
64+
? styles.headerBackTitleFocused
65+
: styles.headerBackTitle
66+
}>
67+
Info
68+
</Text>
69+
</TouchableOpacity>
70+
);
71+
}
72+
3873
/**
3974
* The home screen.
4075
*/
@@ -153,26 +188,17 @@ function Screen({route, navigation}) {
153188
/**
154189
* Construct the options for the navigation header.
155190
*/
191+
192+
let infoButtonFocused = false;
193+
156194
const headerOptions = (title) => {
157195
return {
158196
title,
159197
headerBackTitleStyle: styles.headerBackTitle,
160198
headerStyle: styles.header,
161199
headerTitleContainerStyle: styles.headerTitleContainer,
162200
headerTitleStyle: styles.headerTitle,
163-
// Demo button for the upper right that doesn't do anything.
164-
// It is styled to invisibly extend close to the center of the screen,
165-
// so that it will be reachable by the tvOS focus engine without having
166-
// to implement a TVFocusGuideView.
167-
headerRight: () => (
168-
<TouchableOpacity
169-
style={styles.infoButtonContainer}
170-
onPress={() => alert('Info')} /* eslint-disable-line no-alert */
171-
onFocus={() => console.log('Focus: Info button')}>
172-
<View style={styles.spacer} />
173-
<Text style={styles.headerBackTitle}>Info</Text>
174-
</TouchableOpacity>
175-
),
201+
headerRight: () => <InfoButton />,
176202
};
177203
};
178204

@@ -215,6 +241,7 @@ export default App;
215241
const colors = {
216242
blue: '#0070d2',
217243
white: '#ffffff',
244+
yellow: '#ffdd00',
218245
};
219246

220247
const styles = StyleSheet.create({
@@ -238,6 +265,10 @@ const styles = StyleSheet.create({
238265
fontSize: 40,
239266
color: colors.white,
240267
},
268+
headerBackTitleFocused: {
269+
fontSize: 40,
270+
color: colors.yellow,
271+
},
241272
headerTitleContainer: {
242273
marginTop: 0,
243274
},

0 commit comments

Comments
 (0)