From 0f2d8e662ec0452d5781ef240ec913addc802747 Mon Sep 17 00:00:00 2001 From: Param Aggarwal Date: Mon, 6 Jul 2015 17:29:30 -0700 Subject: [PATCH] [ScrollView] Pick data from older event on coalescing. Summary: The `ScrollView` sends important `updatedChildFrames` data to the `ListView` to be able to implement `onChangeVisibleRows` method. Coalescing operates very strongly on older devices like the iPhone 4s where this data is then lost. Fixes #1782. `ListView` has a method called `onChangeVisibleRows` that is called whenever the rows visible on screen change. This method is critical to be able to implement deletion/creation of views and hence be conservative in memory usage. I have an infinite scrolling view which uses this method to only render the full rows for what is visible on screen and put placeholders for everything else. In the `RCTEventDispatcher`, we [coalesce events](https://github.com/facebook/react-native/blob/522fd33d6f3c8fb339b0dde35b05df34c1233306/React/Base/RCTEventDispatcher.m#L135-L152) that are meant to be sent across the bridge. They are [dequeued](https://github.com/facebook/react-native/blob/522fd33d6f3c8fb339b0dde35b05df34c1233306/React/Base/RCTEventDispatcher.m#L180-L188) on each Closes https://github.com/facebook/react-native/pull/1783 Github Author: Param Aggarwal --- React/Views/RCTScrollView.m | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/React/Views/RCTScrollView.m b/React/Views/RCTScrollView.m index 6c3f5d519c6..2528678493d 100644 --- a/React/Views/RCTScrollView.m +++ b/React/Views/RCTScrollView.m @@ -114,8 +114,16 @@ RCT_NOT_IMPLEMENTED(-init) return YES; } -- (id)coalesceWithEvent:(id)newEvent +- (RCTScrollEvent *)coalesceWithEvent:(RCTScrollEvent *)newEvent { + NSArray *updatedChildFrames = [_userData[@"updatedChildFrames"] arrayByAddingObjectsFromArray:newEvent->_userData[@"updatedChildFrames"]]; + + if (updatedChildFrames) { + NSMutableDictionary *userData = [newEvent->_userData mutableCopy]; + userData[@"updatedChildFrames"] = updatedChildFrames; + newEvent->_userData = userData; + } + return newEvent; }