Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 12 additions & 4 deletions Example/test/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React, { Component } from 'react';
import { StyleSheet, View } from 'react-native';
import { Button, StyleSheet, View } from 'react-native';

import Animated, { Easing } from 'react-native-reanimated';

Expand All @@ -21,6 +21,7 @@ const {
Value,
Clock,
event,
forceStartClock,
} = Animated;

function runSpring(clock, value, dest) {
Expand Down Expand Up @@ -77,7 +78,7 @@ function runTiming(clock, value, dest) {
set(state.position, value),
set(state.frameTime, 0),
set(config.toValue, dest),
startClock(clock),
//startClock(clock),
]),
timing(clock, state, config),
cond(state.finished, debug('stop clock', stopClock(clock))),
Expand All @@ -90,11 +91,12 @@ export default class Example extends Component {
super(props);

// const transX = new Value(0);
const clock = new Clock();
this.clock = new Clock();
this.state = { moving: false };
// const twenty = new Value(20);
// const thirty = new Value(30);
// this._transX = cond(new Value(0), twenty, multiply(3, thirty));
this._transX = runTiming(clock, -120, 120);
this._transX = runTiming(this.clock, -120, 120);
}
componentDidMount() {
// Animated.spring(this._transX, {
Expand All @@ -109,6 +111,12 @@ export default class Example extends Component {
<Animated.View
style={[styles.box, { transform: [{ translateX: this._transX }] }]}
/>
<Button
title="1"
onPress={() => {
forceStartClock(this.clock);
}}
/>
</View>
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,12 @@ public void dropNode(int tag) {
mAnimatedNodes.remove(tag);
}

public void evaluateClock(int clockId) {
Node clock = findNodeById(clockId);
if (clock instanceof ClockNode)
((ClockNode) clock).start();
}

public void connectNodes(int parentID, int childID) {
Node parentNode = mAnimatedNodes.get(parentID);
if (parentNode == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,16 @@ public void execute(NodesManager nodesManager) {
});
}

@ReactMethod
public void evaluateClock(final int nodeID) {
mOperations.add(new UIThreadOperation() {
@Override
public void execute(NodesManager nodesManager) {
nodesManager.evaluateClock(nodeID);
}
});
}

@ReactMethod
public void configureNativeProps(ReadableArray nativePropsArray) {
int size = nativePropsArray.size();
Expand Down
6 changes: 5 additions & 1 deletion src/base.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import AnimatedDebug from './core/AnimatedDebug';
import AnimatedCall from './core/AnimatedCall';
import AnimatedEvent from './core/AnimatedEvent';

import { adapt } from './utils';
import { adapt, evaluateClock } from './utils';

function operator(name) {
return (...args) => new AnimatedOperator(name, args.map(adapt));
Expand Down Expand Up @@ -68,6 +68,10 @@ export const startClock = function(clock) {
return new AnimatedStartClock(clock);
};

export const forceStartClock = function(clock) {
evaluateClock(clock);
};

export const stopClock = function(clock) {
return new AnimatedStopClock(clock);
};
Expand Down
2 changes: 1 addition & 1 deletion src/core/AnimatedNode.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ export default class AnimatedNode {
}

__onEvaluate() {
throw new Excaption('Missing implementation of onEvaluate');
throw new Exception('Missing implementation of onEvaluate');
}

__getProps() {
Expand Down
7 changes: 7 additions & 0 deletions src/utils.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import AnimatedBlock from './core/AnimatedBlock';
import AnimatedNode from './core/AnimatedNode';
import AnimatedValue from './core/AnimatedValue';
import { NativeModules } from 'react-native';

const { ReanimatedModule } = NativeModules;

function nodify(v) {
// TODO: cache some typical static values (e.g. 0, 1, -1)
Expand All @@ -16,3 +19,7 @@ export function adapt(v) {
export function val(v) {
return v && v.__getValue ? v.__getValue() : v || 0;
}

export function evaluateClock(clock) {
ReanimatedModule.evaluateClock(clock.__nodeID);
}