Add support for animated events

Summary:
This adds support for `Animated.event` driven natively. This is WIP and would like feedback on how this is implemented.

At the moment, it works by providing a mapping between a view tag, an event name, an event path and an animated value when a view has a prop with a `AnimatedEvent` object. Then we can hook into `EventDispatcher`, check for events that target our view + event name and update the animated value using the event path.

For now it works with the onScroll event but it should be generic enough to work with anything.
Closes https://github.com/facebook/react-native/pull/9253

Differential Revision: D3759844

Pulled By: foghina

fbshipit-source-id: 86989c705847955bd65e6cf5a7d572ec7ccd3eb4
This commit is contained in:
Janic Duplessis
2016-09-19 04:07:36 -07:00
committed by Facebook Github Bot 9
parent 19d0429a76
commit 6565929358
13 changed files with 527 additions and 34 deletions

View File

@@ -168,6 +168,46 @@ class InternalSettings extends React.Component {
}
}
class EventExample extends React.Component {
state = {
scrollX: new Animated.Value(0),
};
render() {
const opacity = this.state.scrollX.interpolate({
inputRange: [0, 200],
outputRange: [1, 0],
});
return (
<View>
<Animated.View
style={[
styles.block,
{
opacity,
}
]}
/>
<Animated.ScrollView
horizontal
style={{ height: 100, marginTop: 16 }}
onScroll={
Animated.event([{
nativeEvent: { contentOffset: { x: this.state.scrollX } }
}], {
useNativeDriver: true,
})
}
>
<View style={{ width: 600, backgroundColor: '#eee', justifyContent: 'center' }}>
<Text>Scroll me!</Text>
</View>
</Animated.ScrollView>
</View>
);
}
}
const styles = StyleSheet.create({
row: {
padding: 10,
@@ -429,4 +469,13 @@ exports.examples = [
);
},
},
{
title: 'Animated events',
platform: 'android',
render: function() {
return (
<EventExample />
);
},
},
];