diff --git a/Libraries/Components/ScrollView/ScrollView.js b/Libraries/Components/ScrollView/ScrollView.js index d7d982ddb2..09f7b94d65 100644 --- a/Libraries/Components/ScrollView/ScrollView.js +++ b/Libraries/Components/ScrollView/ScrollView.js @@ -5,7 +5,6 @@ */ 'use strict'; -var ArrayOfPropType = require('ArrayOfPropType'); var EdgeInsetsPropType = require('EdgeInsetsPropType'); var Platform = require('Platform'); var PointPropType = require('PointPropType'); @@ -22,11 +21,11 @@ var View = require('View'); var ViewStylePropTypes = require('ViewStylePropTypes'); var createReactIOSNativeComponentClass = require('createReactIOSNativeComponentClass'); +var deepDiffer = require('deepDiffer'); var flattenStyle = require('flattenStyle'); +var insetsDiffer = require('insetsDiffer'); var invariant = require('invariant'); -var merge = require('merge'); -var nativePropType = require('nativePropType'); -var validAttributesFromPropTypes = require('validAttributesFromPropTypes'); +var pointsDiffer = require('pointsDiffer'); var PropTypes = React.PropTypes; @@ -60,37 +59,37 @@ var ScrollView = React.createClass({ }, propTypes: { - automaticallyAdjustContentInsets: nativePropType(PropTypes.bool), // true - contentInset: nativePropType(EdgeInsetsPropType), // zeroes - contentOffset: nativePropType(PointPropType), // zeroes + automaticallyAdjustContentInsets: PropTypes.bool, // true + contentInset: EdgeInsetsPropType, // zeros + contentOffset: PointPropType, // zeros onScroll: PropTypes.func, onScrollAnimationEnd: PropTypes.func, - scrollEnabled: nativePropType(PropTypes.bool), // true - scrollIndicatorInsets: nativePropType(EdgeInsetsPropType), // zeros - showsHorizontalScrollIndicator: nativePropType(PropTypes.bool), - showsVerticalScrollIndicator: nativePropType(PropTypes.bool), + scrollEnabled: PropTypes.bool, // tre + scrollIndicatorInsets: EdgeInsetsPropType, // zeros + showsHorizontalScrollIndicator: PropTypes.bool, + showsVerticalScrollIndicator: PropTypes.bool, style: StyleSheetPropType(ViewStylePropTypes), - throttleScrollCallbackMS: nativePropType(PropTypes.number), // null + throttleScrollCallbackMS: PropTypes.number, // null /** * When true, the scroll view bounces horizontally when it reaches the end * even if the content is smaller than the scroll view itself. The default * value is true when `horizontal={true}` and false otherwise. */ - alwaysBounceHorizontal: nativePropType(PropTypes.bool), + alwaysBounceHorizontal: PropTypes.bool, /** * When true, the scroll view bounces vertically when it reaches the end * even if the content is smaller than the scroll view itself. The default * value is false when `horizontal={true}` and true otherwise. */ - alwaysBounceVertical: nativePropType(PropTypes.bool), + alwaysBounceVertical: PropTypes.bool, /** * When true, the scroll view automatically centers the content when the * content is smaller than the scroll view bounds; when the content is * larger than the scroll view, this property has no effect. The default * value is false. */ - centerContent: nativePropType(PropTypes.bool), + centerContent: PropTypes.bool, /** * These styles will be applied to the scroll view content container which * wraps all of the child views. Example: @@ -113,7 +112,7 @@ var ScrollView = React.createClass({ * - Normal: 0.998 (the default) * - Fast: 0.9 */ - decelerationRate: nativePropType(PropTypes.number), + decelerationRate: PropTypes.number, /** * When true, the scroll view's children are arranged horizontally in a row * instead of vertically in a column. The default value is false. @@ -138,26 +137,26 @@ var ScrollView = React.createClass({ * taps, and the keyboard will not dismiss automatically. The default value * is false. */ - keyboardShouldPersistTaps: nativePropType(PropTypes.bool), + keyboardShouldPersistTaps: PropTypes.bool, /** * The maximum allowed zoom scale. The default value is 1.0. */ - maximumZoomScale: nativePropType(PropTypes.number), + maximumZoomScale: PropTypes.number, /** * The minimum allowed zoom scale. The default value is 1.0. */ - minimumZoomScale: nativePropType(PropTypes.number), + minimumZoomScale: PropTypes.number, /** * When true, the scroll view stops on multiples of the scroll view's size * when scrolling. This can be used for horizontal pagination. The default * value is false. */ - pagingEnabled: nativePropType(PropTypes.bool), + pagingEnabled: PropTypes.bool, /** * When true, the scroll view scrolls to top when the status bar is tapped. * The default value is true. */ - scrollsToTop: nativePropType(PropTypes.bool), + scrollsToTop: PropTypes.bool, /** * An array of child indices determining which children get docked to the * top of the screen when scrolling. For example, passing @@ -165,7 +164,7 @@ var ScrollView = React.createClass({ * top of the scroll view. This property is not supported in conjunction * with `horizontal={true}`. */ - stickyHeaderIndices: nativePropType(ArrayOfPropType(PropTypes.number)), + stickyHeaderIndices: PropTypes.arrayOf(PropTypes.number), /** * Experimental: When true, offscreen child views (whose `overflow` value is * `hidden`) are removed from their native backing superview when offscreen. @@ -176,7 +175,7 @@ var ScrollView = React.createClass({ /** * The current scale of the scroll view content. The default value is 1.0. */ - zoomScale: nativePropType(PropTypes.number), + zoomScale: PropTypes.number, }, mixins: [ScrollResponder.Mixin], @@ -250,32 +249,31 @@ var ScrollView = React.createClass({ this.props.alwaysBounceVertical : !this.props.horizontal; - var props = merge( - this.props, { - alwaysBounceHorizontal, - alwaysBounceVertical, - keyboardDismissMode: this.props.keyboardDismissMode ? - keyboardDismissModeConstants[this.props.keyboardDismissMode] : - undefined, - style: [styles.base, this.props.style], - onTouchStart: this.scrollResponderHandleTouchStart, - onTouchMove: this.scrollResponderHandleTouchMove, - onTouchEnd: this.scrollResponderHandleTouchEnd, - onScrollBeginDrag: this.scrollResponderHandleScrollBeginDrag, - onScrollEndDrag: this.scrollResponderHandleScrollEndDrag, - onMomentumScrollBegin: this.scrollResponderHandleMomentumScrollBegin, - onMomentumScrollEnd: this.scrollResponderHandleMomentumScrollEnd, - onStartShouldSetResponder: this.scrollResponderHandleStartShouldSetResponder, - onStartShouldSetResponderCapture: this.scrollResponderHandleStartShouldSetResponderCapture, - onScrollShouldSetResponder: this.scrollResponderHandleScrollShouldSetResponder, - onScroll: this.scrollResponderHandleScroll, - onResponderGrant: this.scrollResponderHandleResponderGrant, - onResponderTerminationRequest: this.scrollResponderHandleTerminationRequest, - onResponderTerminate: this.scrollResponderHandleTerminate, - onResponderRelease: this.scrollResponderHandleResponderRelease, - onResponderReject: this.scrollResponderHandleResponderReject, - } - ); + var props = { + ...this.props, + alwaysBounceHorizontal, + alwaysBounceVertical, + keyboardDismissMode: this.props.keyboardDismissMode ? + keyboardDismissModeConstants[this.props.keyboardDismissMode] : + undefined, + style: [styles.base, this.props.style], + onTouchStart: this.scrollResponderHandleTouchStart, + onTouchMove: this.scrollResponderHandleTouchMove, + onTouchEnd: this.scrollResponderHandleTouchEnd, + onScrollBeginDrag: this.scrollResponderHandleScrollBeginDrag, + onScrollEndDrag: this.scrollResponderHandleScrollEndDrag, + onMomentumScrollBegin: this.scrollResponderHandleMomentumScrollBegin, + onMomentumScrollEnd: this.scrollResponderHandleMomentumScrollEnd, + onStartShouldSetResponder: this.scrollResponderHandleStartShouldSetResponder, + onStartShouldSetResponderCapture: this.scrollResponderHandleStartShouldSetResponderCapture, + onScrollShouldSetResponder: this.scrollResponderHandleScrollShouldSetResponder, + onScroll: this.scrollResponderHandleScroll, + onResponderGrant: this.scrollResponderHandleResponderGrant, + onResponderTerminationRequest: this.scrollResponderHandleTerminationRequest, + onResponderTerminate: this.scrollResponderHandleTerminate, + onResponderRelease: this.scrollResponderHandleResponderRelease, + onResponderReject: this.scrollResponderHandleResponderReject, + }; var ScrollViewClass; if (Platform.OS === 'ios') { @@ -306,28 +304,44 @@ var styles = StyleSheet.create({ }, }); +var validAttributes = { + ...ReactIOSViewAttributes.UIView, + alwaysBounceHorizontal: true, + alwaysBounceVertical: true, + automaticallyAdjustContentInsets: true, + centerContent: true, + contentInset: insetsDiffer, + contentOffset: pointsDiffer, + decelerationRate: true, + horizontal: true, + keyboardDismissMode: true, + keyboardShouldPersistTaps: true, + maximumZoomScale: true, + minimumZoomScale: true, + pagingEnabled: true, + removeClippedSubviews: true, + scrollEnabled: true, + scrollIndicatorInsets: insetsDiffer, + scrollsToTop: true, + showsHorizontalScrollIndicator: true, + showsVerticalScrollIndicator: true, + stickyHeaderIndices: deepDiffer, + throttleScrollCallbackMS: true, + zoomScale: true, +}; + if (Platform.OS === 'android') { var AndroidScrollView = createReactIOSNativeComponentClass({ - validAttributes: merge( - ReactIOSViewAttributes.UIView, - validAttributesFromPropTypes(ScrollView.propTypes) - ), + validAttributes: validAttributes, uiViewClassName: 'AndroidScrollView', }); - var AndroidHorizontalScrollView = createReactIOSNativeComponentClass({ - validAttributes: merge( - ReactIOSViewAttributes.UIView, - validAttributesFromPropTypes(ScrollView.propTypes) - ), + validAttributes: validAttributes, uiViewClassName: 'AndroidHorizontalScrollView', }); } else if (Platform.OS === 'ios') { var RCTScrollView = createReactIOSNativeComponentClass({ - validAttributes: merge( - ReactIOSViewAttributes.UIView, - validAttributesFromPropTypes(ScrollView.propTypes) - ), + validAttributes: validAttributes, uiViewClassName: 'RCTScrollView', }); } diff --git a/Libraries/ReactIOS/nativePropType.js b/Libraries/ReactIOS/nativePropType.js deleted file mode 100644 index d61c7f1914..0000000000 --- a/Libraries/ReactIOS/nativePropType.js +++ /dev/null @@ -1,18 +0,0 @@ -/** - * Copyright 2004-present Facebook. All Rights Reserved. - * - * @providesModule nativePropType - */ -'use strict' - -/** - * A simple wrapper for prop types to mark them as native, which will allow them - * to be passed over the bridge to be applied to the native component if - * processed by `validAttributesFromPropTypes`. - */ -function nativePropType(propType) { - propType.isNative = true; - return propType; -} - -module.exports = nativePropType; diff --git a/Libraries/StyleSheet/ArrayOfPropType.js b/Libraries/StyleSheet/ArrayOfPropType.js deleted file mode 100644 index 89d224d8b0..0000000000 --- a/Libraries/StyleSheet/ArrayOfPropType.js +++ /dev/null @@ -1,18 +0,0 @@ -/** - * Copyright 2004-present Facebook. All Rights Reserved. - * - * @providesModule ArrayOfPropType - */ -'use strict' - -var ReactPropTypes = require('ReactPropTypes'); - -var deepDiffer = require('deepDiffer'); - -var ArrayOfPropType = (type, differ) => { - var checker = ReactPropTypes.arrayOf(type); - checker.differ = differ ? differ : deepDiffer; - return checker; -}; - -module.exports = ArrayOfPropType; diff --git a/Libraries/StyleSheet/EdgeInsetsPropType.js b/Libraries/StyleSheet/EdgeInsetsPropType.js index dcf38de79c..a57abcaf8f 100644 --- a/Libraries/StyleSheet/EdgeInsetsPropType.js +++ b/Libraries/StyleSheet/EdgeInsetsPropType.js @@ -17,6 +17,4 @@ var EdgeInsetsPropType = createStrictShapeTypeChecker({ right: PropTypes.number, }); -EdgeInsetsPropType.differ = insetsDiffer; - module.exports = EdgeInsetsPropType; diff --git a/Libraries/StyleSheet/PointPropType.js b/Libraries/StyleSheet/PointPropType.js index b281b96e0b..c409bd660a 100644 --- a/Libraries/StyleSheet/PointPropType.js +++ b/Libraries/StyleSheet/PointPropType.js @@ -15,6 +15,4 @@ var PointPropType = createStrictShapeTypeChecker({ y: PropTypes.number, }); -PointPropType.differ = pointsDiffer; - module.exports = PointPropType; diff --git a/Libraries/Utilities/validAttributesFromPropTypes.js b/Libraries/Utilities/validAttributesFromPropTypes.js deleted file mode 100644 index d08d17cfa6..0000000000 --- a/Libraries/Utilities/validAttributesFromPropTypes.js +++ /dev/null @@ -1,20 +0,0 @@ -/** - * Copyright 2004-present Facebook. All Rights Reserved. - * - * @providesModule validAttributesFromPropTypes - */ -'use strict' - -function validAttributesFromPropTypes(propTypes) { - var validAttributes = {}; - for (var key in propTypes) { - var propType = propTypes[key]; - if (propType && propType.isNative) { - var diff = propType.differ; - validAttributes[key] = diff ? {diff} : true; - } - } - return validAttributes; -} - -module.exports = validAttributesFromPropTypes;