Skip to content

Commit 6622ee5

Browse files
Abbondanzometa-codesync[bot]
authored andcommitted
Remove hasTVPreferredFocus (#58700)
Summary: Pull Request resolved: #58700 Remove the deprecated `hasTVPreferredFocus` prop from the core `View`, `Button`, and Touchable APIs and from Android native prop registration and Fabric. Persistent focus eligibility remains available through `focusable`, while imperative focus requests are available through `focus()`. Keep a deprecated no-op `ReactViewManager.setTVPreferredFocus` method solely for binary compatibility with independently compiled `ViewManager` subclasses; it no longer registers a React prop or changes focus. Changelog: [General][Removed] - Remove the deprecated `hasTVPreferredFocus` prop Reviewed By: andrewdacenko Differential Revision: D122080657 fbshipit-source-id: f7fc8b978e5e8c1234ad9bf4c05cba8270fc0558
1 parent 5fc6ccb commit 6622ee5

20 files changed

Lines changed: 71 additions & 171 deletions

File tree

‎packages/react-native/Libraries/Components/Button.js‎

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -56,16 +56,6 @@ type ButtonPropsCore = Readonly<{
5656
*/
5757
color?: ?ColorValue,
5858

59-
/**
60-
* TV preferred focus.
61-
*
62-
* @platform tv
63-
*
64-
* @default `false`
65-
* @deprecated Use `focusable` instead
66-
*/
67-
hasTVPreferredFocus?: ?boolean,
68-
6959
/**
7060
* Designates the next view to receive focus when the user navigates down. See
7161
* the [Android documentation][android:nextFocusDown].
@@ -219,7 +209,6 @@ const Button: component(
219209
onPress,
220210
touchSoundDisabled,
221211
title,
222-
hasTVPreferredFocus,
223212
nextFocusDown,
224213
nextFocusForward,
225214
nextFocusLeft,
@@ -290,7 +279,6 @@ const Button: component(
290279
accessibilityRole="button"
291280
accessibilityState={_accessibilityState}
292281
importantForAccessibility={_importantForAccessibility}
293-
hasTVPreferredFocus={hasTVPreferredFocus}
294282
nextFocusDown={nextFocusDown}
295283
nextFocusForward={nextFocusForward}
296284
nextFocusLeft={nextFocusLeft}

‎packages/react-native/Libraries/Components/Touchable/TouchableHighlight.js‎

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -34,13 +34,6 @@ type AndroidProps = Readonly<{
3434
nextFocusUp?: ?number,
3535
}>;
3636

37-
type IOSProps = Readonly<{
38-
/**
39-
* @deprecated Use `focusable` instead
40-
*/
41-
hasTVPreferredFocus?: ?boolean,
42-
}>;
43-
4437
type TouchableHighlightBaseProps = Readonly<{
4538
/**
4639
* Opacity of the wrapped view when touch is active. Requires `underlayColor` to be set.
@@ -75,7 +68,6 @@ type TouchableHighlightBaseProps = Readonly<{
7568
export type TouchableHighlightProps = Readonly<{
7669
...TouchableWithoutFeedbackProps,
7770
...AndroidProps,
78-
...IOSProps,
7971
...TouchableHighlightBaseProps,
8072
}>;
8173

@@ -281,7 +273,6 @@ class TouchableHighlightImpl extends React.Component<
281273
)}
282274
onLayout={this.props.onLayout}
283275
hitSlop={this.props.hitSlop}
284-
hasTVPreferredFocus={this.props.hasTVPreferredFocus}
285276
nextFocusDown={this.props.nextFocusDown}
286277
nextFocusForward={this.props.nextFocusForward}
287278
nextFocusLeft={this.props.nextFocusLeft}

‎packages/react-native/Libraries/Components/Touchable/TouchableNativeFeedback.js‎

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,6 @@ import * as React from 'react';
2626
import {cloneElement} from 'react';
2727

2828
type TouchableNativeFeedbackTVProps = {
29-
/**
30-
* *(Apple TV only)* TV preferred focus (see documentation for the View component).
31-
*
32-
* @platform ios
33-
* @deprecated Use `focusable` instead
34-
*/
35-
hasTVPreferredFocus?: ?boolean,
36-
3729
/**
3830
* Designates the next view to receive focus when the user navigates down. See the Android documentation.
3931
*
@@ -345,7 +337,6 @@ class TouchableNativeFeedback extends React.Component<
345337
accessibilityLiveRegion: accessibilityLiveRegion,
346338
accessibilityElementsHidden:
347339
this.props['aria-hidden'] ?? this.props.accessibilityElementsHidden,
348-
hasTVPreferredFocus: this.props.hasTVPreferredFocus,
349340
hitSlop: this.props.hitSlop,
350341
focusable:
351342
this.props.focusable !== false &&

‎packages/react-native/Libraries/Components/Touchable/TouchableOpacity.js‎

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,6 @@ import * as React from 'react';
2525
export type TouchableOpacityInstance = HostInstance;
2626

2727
export type TouchableOpacityTVProps = Readonly<{
28-
/**
29-
* *(Apple TV only)* TV preferred focus (see documentation for the View component).
30-
*
31-
* @platform ios
32-
* @deprecated Use `focusable` instead
33-
*/
34-
hasTVPreferredFocus?: ?boolean,
35-
3628
/**
3729
* Designates the next view to receive focus when the user navigates down. See the Android documentation.
3830
*
@@ -261,7 +253,6 @@ class TouchableOpacity extends React.Component<
261253
nextFocusLeft={this.props.nextFocusLeft}
262254
nextFocusRight={this.props.nextFocusRight}
263255
nextFocusUp={this.props.nextFocusUp}
264-
hasTVPreferredFocus={this.props.hasTVPreferredFocus}
265256
hitSlop={this.props.hitSlop}
266257
focusable={
267258
this.props.focusable !== false &&

‎packages/react-native/Libraries/Components/View/ViewPropTypes.js‎

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -305,14 +305,6 @@ export type ViewPropsAndroid = Readonly<{
305305
*/
306306
renderToHardwareTextureAndroid?: ?boolean,
307307

308-
/**
309-
* Whether to force the Android TV focus engine to move focus to this view.
310-
*
311-
* @platform android
312-
* @deprecated Use `focusable` instead
313-
*/
314-
hasTVPreferredFocus?: ?boolean,
315-
316308
/**
317309
* Designates the next view to receive focus when the user navigates down.
318310
* The value is the `nativeID` of the target view.
@@ -390,14 +382,6 @@ export type TVViewPropsIOS = Readonly<{
390382
*/
391383
isTVSelectable?: boolean,
392384

393-
/**
394-
* *(Apple TV only)* May be set to true to force the Apple TV focus engine to move focus to this view.
395-
*
396-
* @platform ios
397-
* @deprecated Use `focusable` instead
398-
*/
399-
hasTVPreferredFocus?: boolean,
400-
401385
/**
402386
* *(Apple TV only)* May be used to change the appearance of the Apple TV parallax effect when this view goes in or out of focus. Defaults to 2.0.
403387
*

‎packages/react-native/Libraries/Components/View/__tests__/View-benchmark-itest.js‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,6 @@ function createViewsWithLargeAmountOfPropsAndStyles(count: number): React.Node {
5353
aria-live={'polite'}
5454
collapsable={false}
5555
focusable={i % 2 === 0}
56-
hasTVPreferredFocus={i % 2 === 0}
5756
id={String(i)}
5857
importantForAccessibility={'no-hide-descendants'}
5958
nativeID={String(i)}

‎packages/react-native/Libraries/Components/View/__tests__/ViewProps-benchmark-itest.js‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@ function buildViewsWithFullPropBag(
3636
aria-live="polite"
3737
collapsable={false}
3838
focusable={i % 2 === 0}
39-
hasTVPreferredFocus={i % 2 === 0}
4039
id={String(i)}
4140
importantForAccessibility="no-hide-descendants"
4241
nativeID={String(i)}

‎packages/react-native/Libraries/NativeComponent/BaseViewConfig.android.js‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -360,7 +360,6 @@ const validAttributesForNonEventProps = {
360360

361361
// ReactViewManager @ReactProps
362362
accessible: true,
363-
hasTVPreferredFocus: true,
364363
nextFocusDown: true,
365364
nextFocusForward: true,
366365
nextFocusLeft: true,

‎packages/react-native/ReactAndroid/src/main/java/com/facebook/react/views/view/ReactViewManager.kt‎

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -124,14 +124,16 @@ public open class ReactViewManager : ReactClippingViewManager<ReactViewGroup>()
124124
view.axOrderList = axOrderList
125125
}
126126

127-
@ReactProp(name = "hasTVPreferredFocus")
128-
public open fun setTVPreferredFocus(view: ReactViewGroup, hasTVPreferredFocus: Boolean) {
129-
if (hasTVPreferredFocus) {
130-
view.isFocusable = true
131-
view.isFocusableInTouchMode = true
132-
view.requestFocus()
133-
}
134-
}
127+
/**
128+
* Retained for binary compatibility with [ReactViewManager] subclasses.
129+
*
130+
* This method no longer registers a React prop or changes view focus.
131+
*/
132+
@Deprecated("Use focusable or focus() instead")
133+
public open fun setTVPreferredFocus(
134+
view: ReactViewGroup,
135+
hasTVPreferredFocus: Boolean,
136+
): Unit = Unit
135137

136138
@ReactProp(name = ViewProps.BACKGROUND_IMAGE, customType = "BackgroundImage")
137139
public open fun setBackgroundImage(view: ReactViewGroup, backgroundImage: ReadableArray?) {

‎packages/react-native/ReactAndroid/src/main/jni/react/fabric/FocusOrderingHelper.cpp‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -207,8 +207,7 @@ void FocusOrderingHelper::traverseAndUpdateNextFocusableElement(
207207
// We only care about focusable elements since only they can be both
208208
// focused and present in the hierarchy
209209
if (currNode->getTraits().check(ShadowNodeTraits::Trait::KeyboardFocusable) ||
210-
(props != nullptr &&
211-
(props->focusable || props->accessible || props->hasTVPreferredFocus))) {
210+
(props != nullptr && (props->focusable || props->accessible))) {
212211
LayoutMetrics nodeLayoutMetrics = uimanager.getRelativeLayoutMetrics(
213212
*currNode, parentShadowNode.get(), {.includeTransform = true});
214213

0 commit comments

Comments
 (0)