revert D4656347 to fix crashes

Reviewed By: jingc

Differential Revision: D4659669

fbshipit-source-id: 2c95c212a19cc8b67ce4ec62963c8374aecb3ef6
This commit is contained in:
Jiajie Zhu 2017-03-06 11:13:49 -08:00 committed by Facebook Github Bot
parent 8f0c16d7af
commit b87f4abf78
6 changed files with 23 additions and 85 deletions

View File

@ -2187,13 +2187,7 @@ function attachNativeEvent(viewRef: any, eventName: string, argMapping: Array<?M
return {
detach() {
eventMappings.forEach((mapping) => {
NativeAnimatedAPI.removeAnimatedEventFromView(
viewTag,
eventName,
mapping.animatedValueTag,
);
});
NativeAnimatedAPI.removeAnimatedEventFromView(viewTag, eventName);
},
};
}

View File

@ -169,10 +169,9 @@ RCT_EXPORT_METHOD(addAnimatedEventToView:(nonnull NSNumber *)viewTag
RCT_EXPORT_METHOD(removeAnimatedEventFromView:(nonnull NSNumber *)viewTag
eventName:(nonnull NSString *)eventName)
animatedNodeTag:(nonnull NSNumber *)animatedNodeTag
{
[_operations addObject:^(RCTNativeAnimatedNodesManager *nodesManager) {
[nodesManager removeAnimatedEventFromView:viewTag eventName:eventName animatedNodeTag:animatedNodeTag];
[nodesManager removeAnimatedEventFromView:viewTag eventName:eventName];
}];
}

View File

@ -70,8 +70,7 @@
eventMapping:(NSDictionary<NSString *, id> *__nonnull)eventMapping;
- (void)removeAnimatedEventFromView:(nonnull NSNumber *)viewTag
eventName:(nonnull NSString *)eventName
animatedNodeTag:(nonnull NSNumber *)animatedNodeTag;
eventName:(nonnull NSString *)eventName;
- (void)handleAnimatedEvent:(nonnull id<RCTEvent>)event;

View File

@ -33,9 +33,7 @@
{
RCTUIManager *_uiManager;
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.
NSMutableDictionary<NSString *, NSMutableArray<RCTEventAnimation *> *> *_eventDrivers;
NSMutableDictionary<NSString *, RCTEventAnimation *> *_eventDrivers;
NSMutableSet<id<RCTAnimationDriver>> *_activeAnimations;
CADisplayLink *_displayLink;
}
@ -266,36 +264,15 @@
NSArray<NSString *> *eventPath = [RCTConvert NSStringArray:eventMapping[@"nativeEventPath"]];
RCTEventAnimation *driver =
[[RCTEventAnimation alloc] initWithEventPath:eventPath valueNode:(RCTValueAnimatedNode *)node];
[[RCTEventAnimation alloc] initWithEventPath:eventPath valueNode:(RCTValueAnimatedNode *)node];
NSString *key = [NSString stringWithFormat:@"%@%@", viewTag, eventName];
if (_eventDrivers[key] != nil) {
[_eventDrivers[key] addObject:driver];
} else {
NSMutableArray<RCTEventAnimation *> *drivers = [NSMutableArray new];
[drivers addObject:driver];
_eventDrivers[key] = drivers;
}
_eventDrivers[[NSString stringWithFormat:@"%@%@", viewTag, eventName]] = driver;
}
- (void)removeAnimatedEventFromView:(nonnull NSNumber *)viewTag
eventName:(nonnull NSString *)eventName
animatedNodeTag:(nonnull NSNumber *)animatedNodeTag
{
NSString *key = [NSString stringWithFormat:@"%@%@", viewTag, eventName];
if (_eventDrivers[key] != nil) {
if (_eventDrivers[key].count == 1) {
[_eventDrivers removeObjectForKey:key];
} else {
NSMutableArray<RCTEventAnimation *> *driversForKey = _eventDrivers[key];
for (NSUInteger i = 0; i < driversForKey.count; i++) {
if (driversForKey[i].valueNode.nodeTag == animatedNodeTag) {
[driversForKey removeObjectAtIndex:i];
break;
}
}
}
}
[_eventDrivers removeObjectForKey:[NSString stringWithFormat:@"%@%@", viewTag, eventName]];
}
- (void)handleAnimatedEvent:(id<RCTEvent>)event
@ -305,12 +282,9 @@
}
NSString *key = [NSString stringWithFormat:@"%@%@", event.viewTag, event.eventName];
NSMutableArray<RCTEventAnimation *> *driversForKey = _eventDrivers[key];
if (driversForKey) {
for (RCTEventAnimation *driver in driversForKey) {
[driver updateWithEvent:event];
}
RCTEventAnimation *driver = _eventDrivers[key];
if (driver) {
[driver updateWithEvent:event];
[self updateAnimations];
}
}

View File

@ -351,11 +351,11 @@ public class NativeAnimatedModule extends ReactContextBaseJavaModule implements
}
@ReactMethod
public void removeAnimatedEventFromView(final int viewTag, final String eventName, final int animatedValueTag) {
public void removeAnimatedEventFromView(final int viewTag, final String eventName) {
mOperations.add(new UIThreadOperation() {
@Override
public void execute(NativeAnimatedNodesManager animatedNodesManager) {
animatedNodesManager.removeAnimatedEventFromView(viewTag, eventName, animatedValueTag);
animatedNodesManager.removeAnimatedEventFromView(viewTag, eventName);
}
});
}

View File

@ -31,9 +31,7 @@ import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.ListIterator;
import java.util.Map;
import java.util.Queue;
@ -57,14 +55,12 @@ import javax.annotation.Nullable;
private final SparseArray<AnimatedNode> mAnimatedNodes = new SparseArray<>();
private final SparseArray<AnimationDriver> mActiveAnimations = new SparseArray<>();
private final SparseArray<AnimatedNode> mUpdatedNodes = new SparseArray<>();
// 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.
private final Map<String, List<EventAnimationDriver>> mEventDrivers = new HashMap<>();
private final Map<String, EventAnimationDriver> mEventDrivers = new HashMap<>();
private final Map<String, Map<String, String>> mCustomEventTypes;
private final UIImplementation mUIImplementation;
private int mAnimatedGraphBFSColor = 0;
// Used to avoid allocating a new array on every frame in `runUpdates` and `onEventDispatch`.
private final List<AnimatedNode> mRunUpdateNodeList = new LinkedList<>();
// Used to avoid allocating a new array on every frame in runUpdates.
private final List<AnimatedNode> mRunUpdateNodeList = new ArrayList<>();
public NativeAnimatedNodesManager(UIManagerModule uiManager) {
mUIImplementation = uiManager.getUIImplementation();
@ -316,32 +312,11 @@ import javax.annotation.Nullable;
}
EventAnimationDriver event = new EventAnimationDriver(pathList, (ValueAnimatedNode) node);
String key = viewTag + eventName;
if (mEventDrivers.containsKey(key)) {
mEventDrivers.get(key).add(event);
} else {
List<EventAnimationDriver> drivers = new ArrayList<>(1);
drivers.add(event);
mEventDrivers.put(key, drivers);
}
mEventDrivers.put(viewTag + eventName, event);
}
public void removeAnimatedEventFromView(int viewTag, String eventName, int animatedValueTag) {
String key = viewTag + eventName;
if (mEventDrivers.containsKey(key)) {
List<EventAnimationDriver> driversForKey = mEventDrivers.get(key);
if (driversForKey.size() == 1) {
mEventDrivers.remove(viewTag + eventName);
} else {
ListIterator<EventAnimationDriver> it = driversForKey.listIterator();
while (it.hasNext()) {
if (it.next().mValueNode.mTag == animatedValueTag) {
it.remove();
break;
}
}
}
}
public void removeAnimatedEventFromView(int viewTag, String eventName) {
mEventDrivers.remove(viewTag + eventName);
}
@Override
@ -359,14 +334,11 @@ import javax.annotation.Nullable;
eventName = customEventType.get("registrationName");
}
List<EventAnimationDriver> driversForKey = mEventDrivers.get(event.getViewTag() + eventName);
if (driversForKey != null) {
for (EventAnimationDriver driver : driversForKey) {
event.dispatch(driver);
mRunUpdateNodeList.add(driver.mValueNode);
}
updateNodes(mRunUpdateNodeList);
mRunUpdateNodeList.clear();
EventAnimationDriver eventDriver = mEventDrivers.get(event.getViewTag() + eventName);
if (eventDriver != null) {
event.dispatch(eventDriver);
updateNodes(Collections.singletonList((AnimatedNode) eventDriver.mValueNode));
}
}
}