Skip to content

Commit 8332713

Browse files
sbuggayfacebook-github-bot
authored andcommitted
Add viewToFocus support for backed views
Summary: Changelog: [Internal] Adds explicit focus support for focusing backed views, like text inputs. Reviewed By: shwanton Differential Revision: D114787998
1 parent df5e6f6 commit 8332713

3 files changed

Lines changed: 24 additions & 2 deletions

File tree

packages/react-native/React/Fabric/Mounting/ComponentViews/TextInput/RCTTextInputComponentView.mm

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -542,9 +542,20 @@ - (void)handleCommand:(const NSString *)commandName args:(const NSArray *)args
542542
RCTTextInputHandleCommand(self, commandName, args);
543543
}
544544

545+
#if TARGET_OS_TV
546+
- (UIView *)viewToFocus
547+
{
548+
return _backedTextInputView;
549+
}
550+
#endif
551+
545552
- (void)focus
546553
{
554+
#if TARGET_OS_TV
555+
[super focus];
556+
#else
547557
[_backedTextInputView becomeFirstResponder];
558+
#endif
548559

549560
const auto &props = static_cast<const TextInputProps &>(*_props);
550561

packages/react-native/React/Fabric/Mounting/ComponentViews/View/RCTViewComponentView.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,11 @@ NS_ASSUME_NONNULL_BEGIN
7575
- (void)finalizeUpdates:(RNComponentViewUpdateMask)updateMask NS_REQUIRES_SUPER;
7676
- (void)prepareForRecycle NS_REQUIRES_SUPER;
7777
- (UIView *)betterHitTest:(CGPoint)point withEvent:(UIEvent *)event;
78+
#if TARGET_OS_TV
79+
- (UIView *)viewToFocus;
80+
- (void)focus;
81+
- (void)blur;
82+
#endif
7883

7984
/*
8085
* This is the label that would be coopted by another element

packages/react-native/React/Fabric/Mounting/ComponentViews/View/RCTViewComponentView.mm

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1799,17 +1799,23 @@ - (RCTSurfaceHostingProxyRootView *)containingRootView
17991799
}
18001800
#endif
18011801

1802+
- (UIView *)viewToFocus
1803+
{
1804+
return self;
1805+
}
1806+
18021807
- (void)focus
18031808
{
1804-
[self becomeFirstResponder];
1809+
UIView *viewToFocus = [self viewToFocus];
1810+
[viewToFocus becomeFirstResponder];
18051811

18061812
#if TARGET_OS_TV
18071813
RCTSurfaceHostingProxyRootView *rootView = [self containingRootView];
18081814
if (rootView == nil) {
18091815
return;
18101816
}
18111817

1812-
rootView.reactPreferredFocusedView = self;
1818+
rootView.reactPreferredFocusedView = viewToFocus;
18131819
[rootView setNeedsFocusUpdate];
18141820
[rootView updateFocusIfNeeded];
18151821
#endif

0 commit comments

Comments
 (0)