Skip to content

Commit

Permalink
Add support for animated events
Browse files Browse the repository at this point in the history
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 facebook/react-native#9253

Differential Revision: D3759844

Pulled By: foghina

fbshipit-source-id: 86989c705847955bd65e6cf5a7d572ec7ccd3eb4
  • Loading branch information
janicduplessis authored and Facebook Github Bot 9 committed Sep 19, 2016
1 parent 25de728 commit 201bdb5
Showing 1 changed file with 49 additions and 0 deletions.
49 changes: 49 additions & 0 deletions UIExplorer/js/NativeAnimationsExample.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -429,4 +469,13 @@ exports.examples = [
);
},
},
{
title: 'Animated events',
platform: 'android',
render: function() {
return (
<EventExample />
);
},
},
];

0 comments on commit 201bdb5

Please sign in to comment.