Skip to content

Commit

Permalink
fix(ios): Fix old content/style used when starting a new transition b…
Browse files Browse the repository at this point in the history
…efore a previous has ended
  • Loading branch information
IjzerenHein committed Feb 9, 2020
1 parent 26495a6 commit 64d8597
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions ios/RNSharedElementNode.m
Expand Up @@ -7,6 +7,7 @@
#import <React/RCTView.h>
#import "RNSharedElementNode.h"
#import "RNSharedElementContent.h"
#import <QuartzCore/QuartzCore.h>

@interface RNSharedElementNodeResolvedSource : NSObject
@property (nonatomic, readonly) UIView* view;
Expand Down Expand Up @@ -38,9 +39,11 @@ @implementation RNSharedElementNode

NSMutableArray* _contentRequests;
RNSharedElementContent* _contentCache;
CFTimeInterval _contentCacheTimeInterval;

NSMutableArray* _styleRequests;
RNSharedElementStyle* _styleCache;
CFTimeInterval _styleCacheTimeInterval;

CADisplayLink* _displayLink;

Expand All @@ -66,8 +69,10 @@ - (instancetype)init:(NSNumber *)reactTag view:(UIView*) view isParent:(BOOL)isP
_hideRefCount = 0;
_contentRequests = nil;
_contentCache = nil;
_contentCacheTimeInterval = 0.0;
_styleRequests = nil;
_styleCache = nil;
_styleCacheTimeInterval = 0.0;
_displayLink = nil;
_resolvedSource = [RNSharedElementNodeResolvedSource sourceWithView:nil];
[self updateResolvedSource:YES];
Expand Down Expand Up @@ -241,7 +246,7 @@ - (long) hideRefCount

- (void) requestContent:(__weak id <RNSharedElementDelegate>) delegate
{
if (_contentCache != nil) {
if (_contentCache != nil && ((CACurrentMediaTime() - _contentCacheTimeInterval) <= 0.3)) {
[delegate didLoadContent:_contentCache node:self];
return;
}
Expand Down Expand Up @@ -312,6 +317,7 @@ - (void) updateContent
//NSLog(@"Content fetched: %@, contentType: %d, size: %@", content, contentType, NSStringFromCGSize(bounds.size));

_contentCache = content;
_contentCacheTimeInterval = CACurrentMediaTime();

NSArray* delegates = _contentRequests;
_contentRequests = nil;
Expand All @@ -334,7 +340,7 @@ - (void)onDisplayLinkUpdate:(CADisplayLink *)sender

- (void) requestStyle:(__weak id <RNSharedElementDelegate>) delegate
{
if (_styleCache != nil) {
if (_styleCache != nil && ((CACurrentMediaTime() - _styleCacheTimeInterval) <= 0.3)) {
[delegate didLoadStyle:_styleCache node:self];
return;
}
Expand Down Expand Up @@ -372,6 +378,7 @@ - (void) updateStyle
}*/

_styleCache = style;
_styleCacheTimeInterval = CACurrentMediaTime();

NSArray* delegates = _styleRequests;
_styleRequests = nil;
Expand Down

0 comments on commit 64d8597

Please sign in to comment.