mirror of
https://github.com/zhigang1992/react-native.git
synced 2026-05-11 19:01:43 +08:00
basic useNativeDriver functionality
Summary: Not super clean, but not terrible. Unfortunately this still relies on the old Paper UIManager calling delegate methods to flush the operations queues. This will work for Marketplace You since Paper will be active, but we need to fix this, along with Animated Events which don't work at all yet. Random aside: it seems like taps are less responsive in fabric vs. paper, at least on iOS. There is a sporadic delay between the touches event coming in nativly to the JS callback invoking the native module function to start the animation - this will need some debugging. Reviewed By: shergin Differential Revision: D14143331 fbshipit-source-id: 63a17eaafa1217d77a532a2716d9f886a96fae59
This commit is contained in:
committed by
Facebook Github Bot
parent
53e15c9e95
commit
ea54ceca13
@@ -7,14 +7,14 @@
|
||||
|
||||
#import "RCTAnimatedNode.h"
|
||||
|
||||
@class RCTUIManager;
|
||||
@class RCTBridge;
|
||||
@class RCTViewPropertyMapper;
|
||||
|
||||
@interface RCTPropsAnimatedNode : RCTAnimatedNode
|
||||
|
||||
- (void)connectToView:(NSNumber *)viewTag
|
||||
viewName:(NSString *)viewName
|
||||
uiManager:(RCTUIManager *)uiManager;
|
||||
bridge:(RCTBridge *)bridge;
|
||||
|
||||
- (void)disconnectFromView:(NSNumber *)viewTag;
|
||||
|
||||
|
||||
@@ -7,6 +7,8 @@
|
||||
|
||||
#import "RCTPropsAnimatedNode.h"
|
||||
|
||||
#import <objc/runtime.h>
|
||||
|
||||
#import <React/RCTLog.h>
|
||||
#import <React/RCTUIManager.h>
|
||||
|
||||
@@ -14,12 +16,33 @@
|
||||
#import "RCTStyleAnimatedNode.h"
|
||||
#import "RCTValueAnimatedNode.h"
|
||||
|
||||
// TODO: Eventually we should just include RCTSurfacePresenter.h, but that pulls in all of fabric
|
||||
// which doesn't compile in open source yet, so we mirror the protocol and duplicate the category
|
||||
// here for now.
|
||||
|
||||
@protocol SyncViewUpdater <NSObject>
|
||||
|
||||
- (BOOL)synchronouslyUpdateViewOnUIThread:(NSNumber *)reactTag props:(NSDictionary *)props;
|
||||
|
||||
@end
|
||||
|
||||
@implementation RCTBridge (SurfacePresenterShadow)
|
||||
|
||||
- (id<SyncViewUpdater>)surfacePresenter
|
||||
{
|
||||
return objc_getAssociatedObject(self, @selector(surfacePresenter));
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
|
||||
@implementation RCTPropsAnimatedNode
|
||||
{
|
||||
NSNumber *_connectedViewTag;
|
||||
NSNumber *_rootTag;
|
||||
NSString *_connectedViewName;
|
||||
__weak RCTUIManager *_uiManager;
|
||||
NSMutableDictionary<NSString *, NSObject *> *_propsDictionary;
|
||||
__weak RCTBridge *_bridge;
|
||||
NSMutableDictionary<NSString *, NSObject *> *_propsDictionary; // TODO: use RawProps or folly::dynamic directly
|
||||
}
|
||||
|
||||
- (instancetype)initWithTag:(NSNumber *)tag
|
||||
@@ -33,18 +56,32 @@
|
||||
|
||||
- (void)connectToView:(NSNumber *)viewTag
|
||||
viewName:(NSString *)viewName
|
||||
uiManager:(RCTUIManager *)uiManager
|
||||
bridge:(RCTBridge *)bridge
|
||||
{
|
||||
_connectedViewTag = viewTag;
|
||||
_connectedViewName = viewName;
|
||||
_uiManager = uiManager;
|
||||
_bridge = bridge;
|
||||
_rootTag = nil;
|
||||
}
|
||||
|
||||
- (void)disconnectFromView:(NSNumber *)viewTag
|
||||
{
|
||||
_connectedViewTag = nil;
|
||||
_connectedViewName = nil;
|
||||
_uiManager = nil;
|
||||
_bridge = nil;
|
||||
_rootTag = nil;
|
||||
}
|
||||
|
||||
- (void)updateView
|
||||
{
|
||||
BOOL fabricUpdateSuccess = [_bridge.surfacePresenter synchronouslyUpdateViewOnUIThread:_connectedViewTag
|
||||
props:_propsDictionary];
|
||||
if (fabricUpdateSuccess) {
|
||||
return;
|
||||
}
|
||||
[_bridge.uiManager synchronouslyUpdateViewOnUIThread:_connectedViewTag
|
||||
viewName:_connectedViewName
|
||||
props:_propsDictionary];
|
||||
}
|
||||
|
||||
- (void)restoreDefaultValues
|
||||
@@ -55,9 +92,7 @@
|
||||
}
|
||||
|
||||
if (_propsDictionary.count) {
|
||||
[_uiManager synchronouslyUpdateViewOnUIThread:_connectedViewTag
|
||||
viewName:_connectedViewName
|
||||
props:_propsDictionary];
|
||||
[self updateView];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -83,12 +118,12 @@
|
||||
if (!_connectedViewTag) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
for (NSNumber *parentTag in self.parentNodes.keyEnumerator) {
|
||||
RCTAnimatedNode *parentNode = [self.parentNodes objectForKey:parentTag];
|
||||
if ([parentNode isKindOfClass:[RCTStyleAnimatedNode class]]) {
|
||||
[self->_propsDictionary addEntriesFromDictionary:[(RCTStyleAnimatedNode *)parentNode propsDictionary]];
|
||||
|
||||
|
||||
} else if ([parentNode isKindOfClass:[RCTValueAnimatedNode class]]) {
|
||||
NSString *property = [self propertyNameForParentTag:parentTag];
|
||||
CGFloat value = [(RCTValueAnimatedNode *)parentNode value];
|
||||
@@ -97,9 +132,7 @@
|
||||
}
|
||||
|
||||
if (_propsDictionary.count) {
|
||||
[_uiManager synchronouslyUpdateViewOnUIThread:_connectedViewTag
|
||||
viewName:_connectedViewName
|
||||
props:_propsDictionary];
|
||||
[self updateView];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -41,12 +41,12 @@ RCT_EXPORT_MODULE();
|
||||
{
|
||||
[super setBridge:bridge];
|
||||
|
||||
_nodesManager = [[RCTNativeAnimatedNodesManager alloc] initWithUIManager:self.bridge.uiManager];
|
||||
_nodesManager = [[RCTNativeAnimatedNodesManager alloc] initWithBridge:self.bridge];
|
||||
_operations = [NSMutableArray new];
|
||||
_preOperations = [NSMutableArray new];
|
||||
|
||||
[bridge.eventDispatcher addDispatchObserver:self];
|
||||
[bridge.uiManager.observerCoordinator addObserver:self];
|
||||
[bridge.uiManager.observerCoordinator addObserver:self]; // TODO: add fabric equivalent?
|
||||
}
|
||||
|
||||
#pragma mark -- API
|
||||
@@ -196,7 +196,7 @@ RCT_EXPORT_METHOD(removeAnimatedEventFromView:(nonnull NSNumber *)viewTag
|
||||
|
||||
#pragma mark - RCTUIManagerObserver
|
||||
|
||||
- (void)uiManagerWillPerformMounting:(RCTUIManager *)uiManager
|
||||
- (void)uiManagerWillPerformMounting:(RCTUIManager *)uiManager // TODO: need fabric equivalent
|
||||
{
|
||||
if (_preOperations.count == 0 && _operations.count == 0) {
|
||||
return;
|
||||
|
||||
@@ -13,7 +13,7 @@
|
||||
|
||||
@interface RCTNativeAnimatedNodesManager : NSObject
|
||||
|
||||
- (nonnull instancetype)initWithUIManager:(nonnull RCTUIManager *)uiManager;
|
||||
- (nonnull instancetype)initWithBridge:(nonnull RCTBridge *)bridge;
|
||||
|
||||
- (void)updateAnimations;
|
||||
|
||||
|
||||
@@ -30,7 +30,7 @@
|
||||
|
||||
@implementation RCTNativeAnimatedNodesManager
|
||||
{
|
||||
__weak RCTUIManager *_uiManager;
|
||||
__weak RCTBridge *_bridge;
|
||||
NSMutableDictionary<NSNumber *, RCTAnimatedNode *> *_animationNodes;
|
||||
// Mapping of a view tag and an event name to a list of event animation drivers. 99% of the time
|
||||
// there will be only one driver per mapping so all code code should be optimized around that.
|
||||
@@ -39,10 +39,10 @@
|
||||
CADisplayLink *_displayLink;
|
||||
}
|
||||
|
||||
- (instancetype)initWithUIManager:(nonnull RCTUIManager *)uiManager
|
||||
- (instancetype)initWithBridge:(nonnull RCTBridge *)bridge
|
||||
{
|
||||
if ((self = [super init])) {
|
||||
_uiManager = uiManager;
|
||||
_bridge = bridge;
|
||||
_animationNodes = [NSMutableDictionary new];
|
||||
_eventDrivers = [NSMutableDictionary new];
|
||||
_activeAnimations = [NSMutableSet new];
|
||||
@@ -124,7 +124,7 @@
|
||||
{
|
||||
RCTAnimatedNode *node = _animationNodes[nodeTag];
|
||||
if ([node isKindOfClass:[RCTPropsAnimatedNode class]]) {
|
||||
[(RCTPropsAnimatedNode *)node connectToView:viewTag viewName:viewName uiManager:_uiManager];
|
||||
[(RCTPropsAnimatedNode *)node connectToView:viewTag viewName:viewName bridge:_bridge];
|
||||
}
|
||||
[node setNeedsUpdate];
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user