mirror of
https://github.com/zhigang1992/react-native.git
synced 2026-04-05 22:38:59 +08:00
Summary: This diff implements NativeAnimation offsets on Android. Running the examples should show no change; however, calling `setOffset()` should offset the final value for any value node by that amount. This brings Android up to date with JS and iOS animation APIs. Closes https://github.com/facebook/react-native/pull/10680 Differential Revision: D4119609 fbshipit-source-id: 96dccdf25f67c64c6787fd9ac762ec841cefc46a
57 lines
2.1 KiB
Java
57 lines
2.1 KiB
Java
/**
|
|
* Copyright (c) 2015-present, Facebook, Inc.
|
|
* All rights reserved.
|
|
*
|
|
* This source code is licensed under the BSD-style license found in the
|
|
* LICENSE file in the root directory of this source tree. An additional grant
|
|
* of patent rights can be found in the PATENTS file in the same directory.
|
|
*/
|
|
|
|
package com.facebook.react.animated;
|
|
|
|
import com.facebook.react.bridge.JavaOnlyMap;
|
|
import com.facebook.react.bridge.ReadableMap;
|
|
import com.facebook.react.bridge.ReadableMapKeySetIterator;
|
|
|
|
import java.util.HashMap;
|
|
import java.util.Map;
|
|
|
|
import javax.annotation.Nullable;
|
|
|
|
/**
|
|
* Native counterpart of style animated node (see AnimatedStyle class in AnimatedImplementation.js)
|
|
*/
|
|
/*package*/ class StyleAnimatedNode extends AnimatedNode {
|
|
|
|
private final NativeAnimatedNodesManager mNativeAnimatedNodesManager;
|
|
private final Map<String, Integer> mPropMapping;
|
|
|
|
StyleAnimatedNode(ReadableMap config, NativeAnimatedNodesManager nativeAnimatedNodesManager) {
|
|
ReadableMap style = config.getMap("style");
|
|
ReadableMapKeySetIterator iter = style.keySetIterator();
|
|
mPropMapping = new HashMap<>();
|
|
while (iter.hasNextKey()) {
|
|
String propKey = iter.nextKey();
|
|
int nodeIndex = style.getInt(propKey);
|
|
mPropMapping.put(propKey, nodeIndex);
|
|
}
|
|
mNativeAnimatedNodesManager = nativeAnimatedNodesManager;
|
|
}
|
|
|
|
public void collectViewUpdates(JavaOnlyMap propsMap) {
|
|
for (Map.Entry<String, Integer> entry : mPropMapping.entrySet()) {
|
|
@Nullable AnimatedNode node = mNativeAnimatedNodesManager.getNodeById(entry.getValue());
|
|
if (node == null) {
|
|
throw new IllegalArgumentException("Mapped style node does not exists");
|
|
} else if (node instanceof TransformAnimatedNode) {
|
|
((TransformAnimatedNode) node).collectViewUpdates(propsMap);
|
|
} else if (node instanceof ValueAnimatedNode) {
|
|
propsMap.putDouble(entry.getKey(), ((ValueAnimatedNode) node).getValue());
|
|
} else {
|
|
throw new IllegalArgumentException("Unsupported type of node used in property node " +
|
|
node.getClass());
|
|
}
|
|
}
|
|
}
|
|
}
|