diff --git a/Examples/UIExplorer/ScrollViewExample.js b/Examples/UIExplorer/ScrollViewExample.js index 62ec410f2..69f3ac9c7 100644 --- a/Examples/UIExplorer/ScrollViewExample.js +++ b/Examples/UIExplorer/ScrollViewExample.js @@ -33,7 +33,7 @@ exports.examples = [ return ( { console.log('onScroll!'); }} - throttleScrollCallbackMS={200} + scrollEventThrottle={200} contentInset={{top: -50}} style={styles.scrollView}> {THUMBS.map(createThumbRow)} diff --git a/Libraries/Components/ScrollView/ScrollView.js b/Libraries/Components/ScrollView/ScrollView.js index 92cdab05a..ba6a2c8b1 100644 --- a/Libraries/Components/ScrollView/ScrollView.js +++ b/Libraries/Components/ScrollView/ScrollView.js @@ -64,7 +64,7 @@ var ScrollView = React.createClass({ showsHorizontalScrollIndicator: PropTypes.bool, showsVerticalScrollIndicator: PropTypes.bool, style: StyleSheetPropType(ViewStylePropTypes), - throttleScrollCallbackMS: PropTypes.number, // null + scrollEventThrottle: PropTypes.number, // null /** * When true, the scroll view bounces horizontally when it reaches the end @@ -211,12 +211,12 @@ var ScrollView = React.createClass({ ); } if (__DEV__) { - if (this.props.onScroll && !this.props.throttleScrollCallbackMS) { + if (this.props.onScroll && !this.props.scrollEventThrottle) { var onScroll = this.props.onScroll; this.props.onScroll = function() { console.log( 'You specified `onScroll` on a but not ' + - '`throttleScrollCallbackMS`. You will only receive one event. ' + + '`scrollEventThrottle`. You will only receive one event. ' + 'Using `16` you get all the events but be aware that it may ' + 'cause frame drops, use a bigger number if you don\'t need as ' + 'much precision.' @@ -325,7 +325,7 @@ var validAttributes = { showsHorizontalScrollIndicator: true, showsVerticalScrollIndicator: true, stickyHeaderIndices: {diff: deepDiffer}, - throttleScrollCallbackMS: true, + scrollEventThrottle: true, zoomScale: true, }; diff --git a/Libraries/CustomComponents/ListView/ListView.js b/Libraries/CustomComponents/ListView/ListView.js index b098fc0dc..ecf446725 100644 --- a/Libraries/CustomComponents/ListView/ListView.js +++ b/Libraries/CustomComponents/ListView/ListView.js @@ -325,8 +325,8 @@ var ListView = React.createClass({ stickyHeaderIndices: sectionHeaderIndices, } ); - if (!props.throttleScrollCallbackMS) { - props.throttleScrollCallbackMS = DEFAULT_SCROLL_CALLBACK_THROTTLE; + if (!props.scrollEventThrottle) { + props.scrollEventThrottle = DEFAULT_SCROLL_CALLBACK_THROTTLE; } return ( diff --git a/React/Views/RCTScrollView.h b/React/Views/RCTScrollView.h index db6aa7edd..f218ea6ea 100644 --- a/React/Views/RCTScrollView.h +++ b/React/Views/RCTScrollView.h @@ -43,7 +43,7 @@ @property (nonatomic, assign) UIEdgeInsets contentInset; @property (nonatomic, assign) BOOL automaticallyAdjustContentInsets; -@property (nonatomic, assign) NSUInteger throttleScrollCallbackMS; +@property (nonatomic, assign) NSTimeInterval scrollEventThrottle; @property (nonatomic, assign) BOOL centerContent; @property (nonatomic, copy) NSArray *stickyHeaderIndices; diff --git a/React/Views/RCTScrollView.m b/React/Views/RCTScrollView.m index e3e1c2f79..0376d2a9c 100644 --- a/React/Views/RCTScrollView.m +++ b/React/Views/RCTScrollView.m @@ -274,7 +274,7 @@ CGFloat const ZINDEX_STICKY_HEADER = 50; _contentInset = UIEdgeInsetsZero; _contentSize = CGSizeZero; - _throttleScrollCallbackMS = 0; + _scrollEventThrottle = 0.0; _lastScrollDispatchTime = CACurrentMediaTime(); _cachedChildFrames = [[NSMutableArray alloc] init]; @@ -393,16 +393,15 @@ RCT_SCROLL_EVENT_HANDLER(scrollViewDidZoom, RCTScrollEventTypeMove) [self updateClippedSubviews]; NSTimeInterval now = CACurrentMediaTime(); - NSTimeInterval throttleScrollCallbackSeconds = _throttleScrollCallbackMS / 1000.0; /** - * TODO: this logic looks wrong, and it may be because it is. Currently, if _throttleScrollCallbackMS + * TODO: this logic looks wrong, and it may be because it is. Currently, if _scrollEventThrottle * is set to zero (the default), the "didScroll" event is only sent once per scroll, instead of repeatedly * while scrolling as expected. However, if you "fix" that bug, ScrollView will generate repeated * warnings, and behave strangely (ListView works fine however), so don't fix it unless you fix that too! */ if (_allowNextScrollNoMatterWhat || - (_throttleScrollCallbackMS != 0 && throttleScrollCallbackSeconds < (now - _lastScrollDispatchTime))) { + (_scrollEventThrottle > 0 && _scrollEventThrottle < (now - _lastScrollDispatchTime))) { // Calculate changed frames NSMutableArray *updatedChildFrames = [[NSMutableArray alloc] init]; diff --git a/React/Views/RCTScrollViewManager.m b/React/Views/RCTScrollViewManager.m index 8001947d1..9c0c56f04 100644 --- a/React/Views/RCTScrollViewManager.m +++ b/React/Views/RCTScrollViewManager.m @@ -39,12 +39,14 @@ RCT_EXPORT_VIEW_PROPERTY(scrollEnabled, BOOL) RCT_EXPORT_VIEW_PROPERTY(scrollsToTop, BOOL) RCT_EXPORT_VIEW_PROPERTY(showsHorizontalScrollIndicator, BOOL) RCT_EXPORT_VIEW_PROPERTY(showsVerticalScrollIndicator, BOOL) -RCT_EXPORT_VIEW_PROPERTY(stickyHeaderIndices, NSNumberArray); -RCT_EXPORT_VIEW_PROPERTY(throttleScrollCallbackMS, double); -RCT_EXPORT_VIEW_PROPERTY(zoomScale, CGFloat); -RCT_EXPORT_VIEW_PROPERTY(contentInset, UIEdgeInsets); -RCT_EXPORT_VIEW_PROPERTY(scrollIndicatorInsets, UIEdgeInsets); -RCT_REMAP_VIEW_PROPERTY(contentOffset, scrollView.contentOffset, CGPoint); +RCT_EXPORT_VIEW_PROPERTY(stickyHeaderIndices, NSNumberArray) +RCT_EXPORT_VIEW_PROPERTY(scrollEventThrottle, NSTimeInterval) +RCT_EXPORT_VIEW_PROPERTY(zoomScale, CGFloat) +RCT_EXPORT_VIEW_PROPERTY(contentInset, UIEdgeInsets) +RCT_EXPORT_VIEW_PROPERTY(scrollIndicatorInsets, UIEdgeInsets) +RCT_REMAP_VIEW_PROPERTY(contentOffset, scrollView.contentOffset, CGPoint) + +RCT_DEPRECATED_VIEW_PROPERTY(throttleScrollCallbackMS, scrollEventThrottle) - (NSDictionary *)constantsToExport { diff --git a/React/Views/RCTViewManager.h b/React/Views/RCTViewManager.h index 5c1c609d3..32babecc9 100644 --- a/React/Views/RCTViewManager.h +++ b/React/Views/RCTViewManager.h @@ -153,4 +153,19 @@ typedef void (^RCTViewManagerUIBlock)(RCTUIManager *uiManager, RCTSparseArray *v #define RCT_IGNORE_SHADOW_PROPERTY(name) \ - (void)set_##name:(id)value forShadowView:(id)view withDefaultView:(id)defaultView {} +/** + * Used for when view property names change. Will log an error when used. + */ +#define RCT_DEPRECATED_VIEW_PROPERTY(oldName, newName) \ +- (void)set_##oldName:(id)json forView:(id)view withDefaultView:(id)defaultView { \ + RCTLogError(@"Property '%s' has been replaced by '%s'.", #oldName, #newName); \ + [self set_##newName:json forView:view withDefaultView:defaultView]; \ +} + +#define RCT_DEPRECATED_SHADOW_PROPERTY(oldName, newName) \ +- (void)set_##oldName:(id)json forShadowView:(id)view withDefaultView:(id)defaultView { \ + RCTLogError(@"Property '%s' has been replaced by '%s'.", #oldName, #newName); \ + [self set_##newName:json forView:view withDefaultView:defaultView]; \ +} + @end