forked from facebook/react-native
-
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.
- Loading branch information
Showing
12 changed files
with
433 additions
and
6 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
/** | ||
* 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. | ||
* | ||
* @providesModule AnimatedClamp | ||
* @flow | ||
* @format | ||
*/ | ||
'use strict'; | ||
|
||
const AnimatedInterpolation = require('./AnimatedInterpolation'); | ||
const AnimatedNode = require('./AnimatedNode'); | ||
const AnimatedValue = require('./AnimatedValue'); | ||
const AnimatedWithChildren = require('./AnimatedWithChildren'); | ||
|
||
import type {InterpolationConfigType} from './AnimatedInterpolation'; | ||
|
||
class AnimatedClamp extends AnimatedWithChildren { | ||
_a: AnimatedNode; | ||
_min: AnimatedNode; | ||
_max: AnimatedNode; | ||
|
||
constructor(a: AnimatedNode, min: AnimatedNode | number, max: AnimatedNode | number) { | ||
super(); | ||
|
||
this._a = a; | ||
this._min = typeof min === 'number' ? new AnimatedValue(min) : min; | ||
this._max = typeof max === 'number' ? new AnimatedValue(max) : max; | ||
} | ||
|
||
__makeNative() { | ||
this._a.__makeNative(); | ||
this._min.__makeNative(); | ||
this._max.__makeNative(); | ||
super.__makeNative(); | ||
} | ||
|
||
interpolate(config: InterpolationConfigType): AnimatedInterpolation { | ||
return new AnimatedInterpolation(this, config); | ||
} | ||
|
||
__getValue(): number { | ||
return Math.min(Math.max(this._a.__getValue(), this._min.__getValue()), this._max.__getValue()); | ||
} | ||
|
||
__attach(): void { | ||
this._a.__addChild(this); | ||
this._min.__addChild(this); | ||
this._max.__addChild(this); | ||
} | ||
|
||
__detach(): void { | ||
this._a.__removeChild(this); | ||
this._min.__removeChild(this); | ||
this._max.__removeChild(this); | ||
super.__detach(); | ||
} | ||
|
||
__getNativeConfig(): any { | ||
return { | ||
type: 'clamp', | ||
input: this._a.__getNativeTag(), | ||
min: this._min.__getNativeTag(), | ||
max: this._max.__getNativeTag(), | ||
}; | ||
} | ||
} | ||
|
||
module.exports = AnimatedClamp; |
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,65 @@ | ||
/** | ||
* 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. | ||
* | ||
* @providesModule AnimatedExponentiation | ||
* @flow | ||
* @format | ||
*/ | ||
'use strict'; | ||
|
||
const AnimatedInterpolation = require('./AnimatedInterpolation'); | ||
const AnimatedNode = require('./AnimatedNode'); | ||
const AnimatedValue = require('./AnimatedValue'); | ||
const AnimatedWithChildren = require('./AnimatedWithChildren'); | ||
|
||
import type {InterpolationConfigType} from './AnimatedInterpolation'; | ||
|
||
class AnimatedExponentiation extends AnimatedWithChildren { | ||
_a: AnimatedNode; | ||
_b: AnimatedNode; | ||
|
||
constructor(a: AnimatedNode | number, b: AnimatedNode | number) { | ||
super(); | ||
this._a = typeof a === 'number' ? new AnimatedValue(a) : a; | ||
this._b = typeof b === 'number' ? new AnimatedValue(b) : b; | ||
} | ||
|
||
__makeNative() { | ||
this._a.__makeNative(); | ||
this._b.__makeNative(); | ||
super.__makeNative(); | ||
} | ||
|
||
__getValue(): number { | ||
return Math.pow(this._a.__getValue(), this._b.__getValue()); | ||
} | ||
|
||
interpolate(config: InterpolationConfigType): AnimatedInterpolation { | ||
return new AnimatedInterpolation(this, config); | ||
} | ||
|
||
__attach(): void { | ||
this._a.__addChild(this); | ||
this._b.__addChild(this); | ||
} | ||
|
||
__detach(): void { | ||
this._a.__removeChild(this); | ||
this._b.__removeChild(this); | ||
super.__detach(); | ||
} | ||
|
||
__getNativeConfig(): any { | ||
return { | ||
type: 'exponentiation', | ||
input: [this._a.__getNativeTag(), this._b.__getNativeTag()], | ||
}; | ||
} | ||
} | ||
|
||
module.exports = AnimatedExponentiation; |
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,12 @@ | ||
/** | ||
* Copyright (c) 2015-present, Facebook, Inc. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
|
||
#import "RCTValueAnimatedNode.h" | ||
|
||
@interface RCTClampAnimatedNode : RCTValueAnimatedNode | ||
|
||
@end |
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 @@ | ||
/** | ||
* 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. | ||
*/ | ||
|
||
#import "RCTClampAnimatedNode.h" | ||
|
||
@implementation RCTClampAnimatedNode | ||
{ | ||
NSNumber *_inputNodeTag; | ||
NSNumber *_minNodeTag; | ||
NSNumber *_maxNodeTag; | ||
} | ||
|
||
- (instancetype)initWithTag:(NSNumber *)tag | ||
config:(NSDictionary<NSString *, id> *)config | ||
{ | ||
if (self = [super initWithTag:tag config:config]) { | ||
_inputNodeTag = config[@"input"]; | ||
_minNodeTag = config[@"min"]; | ||
_maxNodeTag = config[@"max"]; | ||
} | ||
|
||
return self; | ||
} | ||
|
||
- (void)performUpdate | ||
{ | ||
[super performUpdate]; | ||
|
||
RCTValueAnimatedNode *input = (RCTValueAnimatedNode *)[self.parentNodes objectForKey:_inputNodeTag]; | ||
RCTValueAnimatedNode *min = (RCTValueAnimatedNode *)[self.parentNodes objectForKey:_minNodeTag]; | ||
RCTValueAnimatedNode *max = (RCTValueAnimatedNode *)[self.parentNodes objectForKey:_maxNodeTag]; | ||
|
||
if ([input isKindOfClass:[RCTValueAnimatedNode class]] && | ||
[min isKindOfClass:[RCTValueAnimatedNode class]] && | ||
[max isKindOfClass:[RCTValueAnimatedNode class]]) { | ||
self.value = MIN(MAX(input.value, min.value), max.value); | ||
} | ||
} | ||
|
||
@end |
14 changes: 14 additions & 0 deletions
14
Libraries/NativeAnimation/Nodes/RCTExponentiationAnimatedNode.h
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,14 @@ | ||
/** | ||
* 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. | ||
*/ | ||
|
||
#import "RCTValueAnimatedNode.h" | ||
|
||
@interface RCTExponentiationAnimatedNode : RCTValueAnimatedNode | ||
|
||
@end |
29 changes: 29 additions & 0 deletions
29
Libraries/NativeAnimation/Nodes/RCTExponentiationAnimatedNode.m
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,29 @@ | ||
/** | ||
* 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. | ||
*/ | ||
|
||
#import "RCTExponentiationAnimatedNode.h" | ||
|
||
@implementation RCTExponentiationAnimatedNode | ||
|
||
- (void)performUpdate | ||
{ | ||
[super performUpdate]; | ||
|
||
NSArray<NSNumber *> *inputNodes = self.config[@"input"]; | ||
if (inputNodes.count > 1) { | ||
RCTValueAnimatedNode *parent1 = (RCTValueAnimatedNode *)[self.parentNodes objectForKey:inputNodes[0]]; | ||
RCTValueAnimatedNode *parent2 = (RCTValueAnimatedNode *)[self.parentNodes objectForKey:inputNodes[1]]; | ||
if ([parent1 isKindOfClass:[RCTValueAnimatedNode class]] && | ||
[parent2 isKindOfClass:[RCTValueAnimatedNode class]]) { | ||
self.value = pow(parent1.value, parent2.value); | ||
} | ||
} | ||
} | ||
|
||
@end |
Oops, something went wrong.