forked from microsoft/react-native-windows
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(Animated): Adds support for DiffClamp node
Add support for DiffClamp node on Windows for `Animated.diffClamp` that was added in facebook/react-native#9419.
- Loading branch information
Showing
3 changed files
with
50 additions
and
0 deletions.
There are no files selected for viewing
46 changes: 46 additions & 0 deletions
46
ReactWindows/ReactNative/Animated/DiffClampAnimatedNode.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
using Newtonsoft.Json.Linq; | ||
using System; | ||
|
||
namespace ReactNative.Animated | ||
{ | ||
class DiffClampAnimatedNode : ValueAnimatedNode | ||
{ | ||
private readonly NativeAnimatedNodesManager _nativeAnimatedNodesManager; | ||
private readonly int _inputNodeTag; | ||
private readonly double _min; | ||
private readonly double _max; | ||
|
||
private double _lastValue; | ||
|
||
public DiffClampAnimatedNode(int tag, JObject config, NativeAnimatedNodesManager nativeAnimatedNodesManager) | ||
: base(tag, config) | ||
{ | ||
_nativeAnimatedNodesManager = nativeAnimatedNodesManager; | ||
_inputNodeTag = config.Value<int>("input"); | ||
_min = config.Value<double>("min"); | ||
_max = config.Value<double>("max"); | ||
|
||
Value = _lastValue = GetInputNodeValue(); | ||
} | ||
|
||
public override void Update() | ||
{ | ||
var value = GetInputNodeValue(); | ||
|
||
var diff = value - _lastValue; | ||
_lastValue = value; | ||
Value = Math.Min(Math.Max(Value + diff, _min), _max); | ||
} | ||
|
||
private double GetInputNodeValue() | ||
{ | ||
var valueAnimatedNode = _nativeAnimatedNodesManager.GetNodeById(_inputNodeTag) as ValueAnimatedNode; | ||
if (valueAnimatedNode == null) { | ||
throw new InvalidOperationException( | ||
"Illegal node ID set as an input for Animated.DiffClamp node."); | ||
} | ||
|
||
return valueAnimatedNode.Value; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters