Skip to content

Commit

Permalink
Bug fix for nil TVView on pop
Browse files Browse the repository at this point in the history
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 65513e5
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion React/Views/RCTTVView.m
Expand Up @@ -173,9 +173,11 @@ - (void)setHasTVPreferredFocus:(BOOL)hasTVPreferredFocus
if (hasTVPreferredFocus) { if (hasTVPreferredFocus) {
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1.0 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{ dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1.0 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
UIView *rootview = self; UIView *rootview = self;
while(![rootview isReactRootView]) { while (![rootview isReactRootView] && rootview != nil) {
rootview = [rootview superview]; rootview = [rootview superview];
} }
if (rootview == nil) return;

rootview = [rootview superview]; rootview = [rootview superview];


[(RCTRootView *)rootview setReactPreferredFocusedView:self]; [(RCTRootView *)rootview setReactPreferredFocusedView:self];
Expand Down

0 comments on commit 65513e5

Please sign in to comment.