Skip to content

Commit 8c9d97b

Browse files
fix focus issue
1 parent 8dc1ee1 commit 8c9d97b

File tree

3 files changed

+4
-6
lines changed

3 files changed

+4
-6
lines changed

packages/app-harness/src/app/index.tsx

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -72,10 +72,7 @@ const AppContent = () => {
7272
if (isWebBased && isFactorTv && focusableRefs[0]?.current) {
7373
focusableRefs[0].current.focus();
7474
setFocusedIndex(0);
75-
} else if (!isWebBased) {
76-
// Set the initial AndroidTV and tvOS focus to be on the button
77-
focusableRefs[0]?.current?.setNativeProps({ hasTVPreferredFocus: true });
78-
}
75+
}
7976
return () => {
8077
removeNotificationListeners(handleNotification);
8178
};
@@ -161,6 +158,7 @@ const AppContent = () => {
161158
focusedIndex === 0 && styles.buttonFocused,
162159
isWebBased && isFactorTv && { outline: 'none' },
163160
]}
161+
hasTVPreferredFocus={!isWebBased && isFactorTv}
164162
/>
165163
</TestCase>
166164
<TestCase id={3} title="Orientation support ">

packages/app-harness/src/components/NewModuleButton/index.native.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { testProps } from '../../config';
66

77
type ButtonProps = TouchableOpacityProps;
88
export const NewModuleButton = forwardRef<React.ElementRef<typeof TouchableOpacity>, ButtonProps>(
9-
({ onBlur, onFocus, style }, ref) => {
9+
({ onBlur, onFocus, style,hasTVPreferredFocus }, ref) => {
1010
const { TestNativeModule } = NativeModules;
1111
const { logDebug } = useLoggerContext();
1212
const callback = (error: any, result: string) => {
@@ -24,7 +24,7 @@ export const NewModuleButton = forwardRef<React.ElementRef<typeof TouchableOpaci
2424
}
2525
};
2626
return (
27-
<TouchableOpacity ref={ref} onPress={onPress} onFocus={onFocus} onBlur={onBlur} style={style}>
27+
<TouchableOpacity ref={ref} onPress={onPress} onFocus={onFocus} onBlur={onBlur} style={style} hasTVPreferredFocus={hasTVPreferredFocus}>
2828
<Text style={styles.buttonTitle} {...testProps('app-harness-home-native-call-button')}>
2929
Click to invoke native module!
3030
</Text>
File renamed without changes.

0 commit comments

Comments
 (0)