@@ -18,11 +18,14 @@ import {createStackNavigator} from '@react-navigation/stack';
18
18
/**
19
19
* We use this Button component instead of the one from react-native,
20
20
* 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.
22
23
*/
23
24
function Button ( { title, onPress, onFocus, isTVSelectable} ) {
24
25
return (
25
26
< TouchableOpacity
27
+ tvParallaxProperties = { { magnification : 1.2 } }
28
+ activeOpacity = { 1.0 }
26
29
onPress = { ( ) => onPress ( ) }
27
30
onFocus = { ( ) => onFocus ( ) }
28
31
isTVSelectable = { isTVSelectable } >
@@ -35,6 +38,38 @@ Button.defaultProps = {
35
38
isTVSelectable : true ,
36
39
} ;
37
40
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
+
38
73
/**
39
74
* The home screen.
40
75
*/
@@ -153,26 +188,17 @@ function Screen({route, navigation}) {
153
188
/**
154
189
* Construct the options for the navigation header.
155
190
*/
191
+
192
+ let infoButtonFocused = false ;
193
+
156
194
const headerOptions = ( title ) => {
157
195
return {
158
196
title,
159
197
headerBackTitleStyle : styles . headerBackTitle ,
160
198
headerStyle : styles . header ,
161
199
headerTitleContainerStyle : styles . headerTitleContainer ,
162
200
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 /> ,
176
202
} ;
177
203
} ;
178
204
@@ -215,6 +241,7 @@ export default App;
215
241
const colors = {
216
242
blue : '#0070d2' ,
217
243
white : '#ffffff' ,
244
+ yellow : '#ffdd00' ,
218
245
} ;
219
246
220
247
const styles = StyleSheet . create ( {
@@ -238,6 +265,10 @@ const styles = StyleSheet.create({
238
265
fontSize : 40 ,
239
266
color : colors . white ,
240
267
} ,
268
+ headerBackTitleFocused : {
269
+ fontSize : 40 ,
270
+ color : colors . yellow ,
271
+ } ,
241
272
headerTitleContainer : {
242
273
marginTop : 0 ,
243
274
} ,
0 commit comments