-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Fix race-condition during render #5187
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 3 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,7 @@ | ||
| #import <RNReanimated/REAAnimationsManager.h> | ||
|
|
||
| @interface REASwizzledUIManager : NSObject | ||
| - (void)setIsViewTreesSynchronized:(NSNumber *)isViewTreesSynchronized; | ||
| - (instancetype)initWithUIManager:(RCTUIManager *)uiManager | ||
| withAnimationManager:(REAAnimationsManager *)animationsManager; | ||
| @end |
| Original file line number | Diff line number | Diff line change | ||||||
|---|---|---|---|---|---|---|---|---|
|
|
@@ -9,6 +9,7 @@ | |||||||
| #import <React/RCTUIManager.h> | ||||||||
|
|
||||||||
| @interface RCTUIManager (Reanimated) | ||||||||
| @property (atomic) NSNumber *isViewTreesSynchronized; | ||||||||
| @property REAAnimationsManager *animationsManager; | ||||||||
| - (NSArray<id<RCTComponent>> *)_childrenToRemoveFromContainer:(id<RCTComponent>)container | ||||||||
| atIndices:(NSArray<NSNumber *> *)atIndices; | ||||||||
|
|
@@ -24,15 +25,28 @@ - (id)animationsManager | |||||||
| { | ||||||||
| return objc_getAssociatedObject(self, @selector(animationsManager)); | ||||||||
| } | ||||||||
|
|
||||||||
| @dynamic isViewTreesSynchronized; | ||||||||
| - (void)setIsViewTreesSynchronized:(NSNumber *)isViewTreesSynchronized | ||||||||
| { | ||||||||
| objc_setAssociatedObject(self, @selector(isViewTreesSynchronized), isViewTreesSynchronized, OBJC_ASSOCIATION_RETAIN); | ||||||||
| } | ||||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||
| - (id)isViewTreesSynchronized | ||||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||
| { | ||||||||
| return objc_getAssociatedObject(self, @selector(isViewTreesSynchronized)); | ||||||||
| } | ||||||||
| @end | ||||||||
|
|
||||||||
| @implementation REASwizzledUIManager | ||||||||
| @implementation REASwizzledUIManager { | ||||||||
| NSMutableDictionary<NSNumber *, REAUIView *> *_viewRegistry; | ||||||||
| } | ||||||||
|
|
||||||||
| - (instancetype)initWithUIManager:(RCTUIManager *)uiManager | ||||||||
| withAnimationManager:(REAAnimationsManager *)animationsManager | ||||||||
| { | ||||||||
| if (self = [super init]) { | ||||||||
| [uiManager setAnimationsManager:animationsManager]; | ||||||||
| [uiManager setIsViewTreesSynchronized:@(1)]; | ||||||||
| [self swizzleMethods]; | ||||||||
| } | ||||||||
| return self; | ||||||||
|
|
@@ -66,6 +80,15 @@ - (void)reanimated_manageChildren:(NSNumber *)containerTag | |||||||
| removeAtIndices:(NSArray<NSNumber *> *)removeAtIndices | ||||||||
| registry:(NSMutableDictionary<NSNumber *, id<RCTComponent>> *)registry | ||||||||
| { | ||||||||
| BOOL isUIViewRegistry = (id)registry == (id)_viewRegistry; | ||||||||
| if (!isUIViewRegistry) { | ||||||||
| // The `isViewTreesSynchronized` flag is necessary to prevent Reanimated from performing | ||||||||
| // synchronous updates when there is inconsistency between the shadow tree and native tree. | ||||||||
| // More details here: https://github.com/software-mansion/react-native-reanimated/pull/5187 | ||||||||
| [self setIsViewTreesSynchronized:@(1)]; | ||||||||
| } else { | ||||||||
| [self setIsViewTreesSynchronized:@(0)]; | ||||||||
| } | ||||||||
| bool isLayoutAnimationEnabled = reanimated::FeaturesConfig::isLayoutAnimationEnabled(); | ||||||||
| id<RCTComponent> container; | ||||||||
| NSArray<id<RCTComponent>> *permanentlyRemovedChildren; | ||||||||
|
|
||||||||
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -34,6 +34,8 @@ - (void)updateView:(nonnull NSNumber *)reactTag viewName:(NSString *)viewName pr | |||||
|
|
||||||
| - (void)setNeedsLayout; | ||||||
|
|
||||||
| - (id)isViewTreesSynchronized; | ||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
|
|
||||||
| @end | ||||||
|
|
||||||
| @interface RCTUIManager (SyncUpdates) | ||||||
|
|
@@ -336,8 +338,10 @@ - (void)performOperations | |||||
| if (strongSelf == nil) { | ||||||
| return; | ||||||
| } | ||||||
| BOOL canUpdateSynchronously = trySynchronously && ![strongSelf.uiManager hasEnqueuedUICommands]; | ||||||
|
|
||||||
| auto isViewTreesSynchronized = [[strongSelf.uiManager isViewTreesSynchronized] intValue] == 1; | ||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
| BOOL canUpdateSynchronously = | ||||||
| trySynchronously && ![strongSelf.uiManager hasEnqueuedUICommands] && !isViewTreesSynchronized; | ||||||
| if (!canUpdateSynchronously) { | ||||||
| [syncUpdateObserver unblockUIThread]; | ||||||
| } | ||||||
|
|
||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It needs to be NSNumber, because I can't inject BOOL field with
objc_setAssociatedObjectmethod