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 https://github.com/facebook/react-native/pull/12073

Differential Revision: D4468989

Pulled By: ericvicenti

fbshipit-source-id: 7926c887035722c983c41cb6b6d9df567010c2ee
This commit is contained in:
Eric Vicenti 2017-01-26 09:41:20 -08:00 committed by Facebook Github Bot
parent 3ab9137b9e
commit 65513e501a
1 changed files with 3 additions and 1 deletions

View File

@ -173,9 +173,11 @@ RCT_NOT_IMPLEMENTED(- (instancetype)initWithCoder:unused)
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];