-
Notifications
You must be signed in to change notification settings - Fork 24.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
iOS: Fix Animated image crash when CADisplayLink target in RCTWeakPro…
…xy is nil Summary: ## Problem When self is nil, this may crash in RCTUIImageViewAnimated.m. ``` _displayLink = [CADisplayLink displayLinkWithTarget:[RCTWeakProxy weakProxyWithTarget:self] selector:selector(displayDidRefresh:)]; ``` ## Fix Replace `RCTWeakProxy` with a concrete class `RCTDisplayWeakRefreshable` that has the displayDidRefresh method, that calls the displayDidRefresh method in its weak target. ### Original Github Issue #28070 (comment) Changelog: [iOS] [Fixed] - Fix Animated image crash when CADisplayLink target in RCTWeakProxy is nil Reviewed By: shergin Differential Revision: D21419385 fbshipit-source-id: da7c3c38f81ea54f633da7f59359e07680ea2faf
- Loading branch information
1 parent
649e1b7
commit e5a6655
Showing
4 changed files
with
87 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
/* | ||
* Copyright (c) Facebook, Inc. and its affiliates. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
|
||
#import <Foundation/Foundation.h> | ||
|
||
@protocol RCTDisplayRefreshable | ||
|
||
- (void)displayDidRefresh:(CADisplayLink *)displayLink; | ||
|
||
@end | ||
|
||
@interface RCTDisplayWeakRefreshable : NSObject | ||
|
||
@property (nonatomic, weak) id<RCTDisplayRefreshable> refreshable; | ||
|
||
+ (CADisplayLink *)displayLinkWithWeakRefreshable:(id<RCTDisplayRefreshable>)refreshable; | ||
|
||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
/* | ||
* Copyright (c) Facebook, Inc. and its affiliates. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
|
||
#import "RCTDisplayWeakRefreshable.h" | ||
|
||
@implementation RCTDisplayWeakRefreshable | ||
|
||
+ (CADisplayLink *)displayLinkWithWeakRefreshable:(id<RCTDisplayRefreshable>)refreshable { | ||
RCTDisplayWeakRefreshable *target = [[RCTDisplayWeakRefreshable alloc] initWithRefreshable:refreshable]; | ||
return [CADisplayLink displayLinkWithTarget:target selector:@selector(displayDidRefresh:)]; | ||
} | ||
|
||
- (instancetype)initWithRefreshable:(id<RCTDisplayRefreshable>)refreshable | ||
{ | ||
if (self = [super init]) { | ||
_refreshable = refreshable; | ||
} | ||
return self; | ||
} | ||
|
||
- (void)displayDidRefresh:(CADisplayLink *)displayLink { | ||
[_refreshable displayDidRefresh:displayLink]; | ||
} | ||
|
||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters