mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
e6cb02d61a
Summary: Rather than specifying Babel plugins in the `.babelrc` packaged with react-native, leverage a Babel preset to define the plugins (https://github.com/exponentjs/babel-preset-react-native). This allows for a much better user experience for those who want (or need) to override options in their project's `.babelrc`. Prior to this PR, if a user wanted to use a custom babel-plugin (or a custom set of babel plugins), they'd have either 1) manually override the `.babelrc` in the react-packager directory (or fork RN), or 2) specify a custom transformer to use when running the packager that loaded their own `.babelrc`. Note - the custom transformer was necessary because without it, RN's `.babelrc` options would supersede the options defined in the project's `.babelrc`...potentially causing issues with plugin ordering. This PR makes the transformer check for the existence of a project-level `.babelrc`, and if it it's there, it _doesn't_ use the react-native `.babelrc`. This prevents any oddities with Babel plug Closes https://github.com/facebook/react-native/pull/5214 Reviewed By: davidaurelio Differential Revision: D2881814 Pulled By: martinbigio fb-gh-sync-id: 4168144b7a365fae62bbeed094d8a03a48b4798c
136 lines
3.3 KiB
JavaScript
136 lines
3.3 KiB
JavaScript
/**
|
|
* @providesModule ScrollViewTestModule
|
|
*/
|
|
|
|
'use strict';
|
|
|
|
var BatchedBridge = require('BatchedBridge');
|
|
var React = require('React');
|
|
var View = require('View');
|
|
var ScrollView = require('ScrollView');
|
|
var Text = require('Text');
|
|
var StyleSheet = require('StyleSheet');
|
|
var TouchableWithoutFeedback = require('TouchableWithoutFeedback');
|
|
var ScrollListener = require('NativeModules').ScrollListener;
|
|
|
|
var NUM_ITEMS = 100;
|
|
|
|
// Shared by integration tests for ScrollView and HorizontalScrollView
|
|
|
|
var scrollViewApp;
|
|
|
|
var Item = React.createClass({
|
|
render: function() {
|
|
return (
|
|
<TouchableWithoutFeedback onPress={this.props.onPress}>
|
|
<View style={styles.item_container}>
|
|
<Text style={styles.item_text}>{this.props.text}</Text>
|
|
</View>
|
|
</TouchableWithoutFeedback>
|
|
);
|
|
},
|
|
});
|
|
|
|
var getInitialState = function() {
|
|
var data = [];
|
|
for (var i = 0; i < NUM_ITEMS; i++) {
|
|
data[i] = {text: 'Item ' + i + '!'};
|
|
}
|
|
return {
|
|
data: data,
|
|
};
|
|
};
|
|
|
|
var onScroll = function(e) {
|
|
ScrollListener.onScroll(e.nativeEvent.contentOffset.x, e.nativeEvent.contentOffset.y);
|
|
};
|
|
|
|
var onScrollBeginDrag = function(e) {
|
|
ScrollListener.onScrollBeginDrag(e.nativeEvent.contentOffset.x, e.nativeEvent.contentOffset.y);
|
|
};
|
|
|
|
var onScrollEndDrag = function(e) {
|
|
ScrollListener.onScrollEndDrag(e.nativeEvent.contentOffset.x, e.nativeEvent.contentOffset.y);
|
|
};
|
|
|
|
var onItemPress = function(itemNumber) {
|
|
ScrollListener.onItemPress(itemNumber);
|
|
};
|
|
|
|
var ScrollViewTestApp = React.createClass({
|
|
getInitialState: getInitialState,
|
|
onScroll: onScroll,
|
|
onItemPress: onItemPress,
|
|
onScrollBeginDrag: onScrollBeginDrag,
|
|
onScrollEndDrag: onScrollEndDrag,
|
|
|
|
scrollTo: function(destX, destY) {
|
|
this.refs.scrollView.scrollTo(destY, destX);
|
|
},
|
|
|
|
render: function() {
|
|
scrollViewApp = this;
|
|
var children = this.state.data.map((item, index) => (
|
|
<Item
|
|
key={index} text={item.text}
|
|
onPress={this.onItemPress.bind(this, index)} />
|
|
));
|
|
return (
|
|
<ScrollView onScroll={this.onScroll} onScrollBeginDrag={this.onScrollBeginDrag} onScrollEndDrag={this.onScrollEndDrag} ref="scrollView">
|
|
{children}
|
|
</ScrollView>
|
|
);
|
|
},
|
|
});
|
|
|
|
var HorizontalScrollViewTestApp = React.createClass({
|
|
getInitialState: getInitialState,
|
|
onScroll: onScroll,
|
|
onItemPress: onItemPress,
|
|
|
|
scrollTo: function(destX, destY) {
|
|
this.refs.scrollView.scrollTo(destY, destX);
|
|
},
|
|
|
|
render: function() {
|
|
scrollViewApp = this;
|
|
var children = this.state.data.map((item, index) => (
|
|
<Item
|
|
key={index} text={item.text}
|
|
onPress={this.onItemPress.bind(this, index)} />
|
|
));
|
|
return (
|
|
<ScrollView horizontal={true} onScroll={this.onScroll} ref="scrollView">
|
|
{children}
|
|
</ScrollView>
|
|
);
|
|
},
|
|
});
|
|
|
|
var styles = StyleSheet.create({
|
|
item_container: {
|
|
padding: 30,
|
|
backgroundColor: '#ffffff',
|
|
},
|
|
item_text: {
|
|
flex: 1,
|
|
fontSize: 18,
|
|
alignSelf: 'center',
|
|
},
|
|
});
|
|
|
|
var ScrollViewTestModule = {
|
|
ScrollViewTestApp: ScrollViewTestApp,
|
|
HorizontalScrollViewTestApp: HorizontalScrollViewTestApp,
|
|
scrollTo: function(destX, destY) {
|
|
scrollViewApp.scrollTo(destX, destY);
|
|
},
|
|
};
|
|
|
|
BatchedBridge.registerCallableModule(
|
|
'ScrollViewTestModule',
|
|
ScrollViewTestModule
|
|
);
|
|
|
|
module.exports = ScrollViewTestModule;
|