Permalink
Browse files

Bug fix for nil TVView on pop

Summary:
Explain the **motivation** for making this change. What existing problem does the pull request solve?

This change is required when you try to set a focus on a view that doesn't exist and thus cannot be focused. In my specific use case, this occurred when trying to set a focus on a list item in a setInterval when the View (with the specific list item) had been popped. The while loop ran infinitely (eventually freezing the app) since the rootView doesn't exist. This adds that check and breaks out if so.

All obj-c tests ran successfully.

dlowder-salesforce
Closes #12073

Differential Revision: D4468989

Pulled By: ericvicenti

fbshipit-source-id: 7926c887035722c983c41cb6b6d9df567010c2ee
  • Loading branch information...
ericvicenti authored and facebook-github-bot committed Jan 26, 2017
1 parent 3ab9137 commit 65513e501a53564d5cf686314135f7062e86bee3
Showing with 3 additions and 1 deletion.
  1. +3 −1 React/Views/RCTTVView.m
View
@@ -173,9 +173,11 @@ - (void)setHasTVPreferredFocus:(BOOL)hasTVPreferredFocus
if (hasTVPreferredFocus) {
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1.0 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
UIView *rootview = self;
while(![rootview isReactRootView]) {
while (![rootview isReactRootView] && rootview != nil) {
rootview = [rootview superview];
}
if (rootview == nil) return;
rootview = [rootview superview];
[(RCTRootView *)rootview setReactPreferredFocusedView:self];

0 comments on commit 65513e5

Please sign in to comment.