I'm trying to extend the current Picker component for ios in react native:
https://github.com/facebook/react-native/blob/master/React/Views/RCTPicker.m
https://github.com/facebook/react-native/blob/master/React/Views/RCTPickerManager.m
I would like to add the possibility to listen for startDragging and endDragging, startDecelerating and endDecelerating events.
I've found there that we can actually know if the user is currently dragging the Picker by checking its subviews dragging
and decelerating
flags. That's good but an event/delegate like pattern would suit the React native bridging model better.
Could you please suggest me how to listen to the Picker subviews dragging
and decelerating
values changes?
--- EDIT ---
Here is what I've tried so far:
I edited the Picker Manager file and added this:
// ...
@implementation RCTPickerManager
RCT_EXPORT_MODULE()
- (UIView *)view
{
//return [RCTPicker new];
RCTPicker* picker = [RCTPicker new];
[self setDelegateForScrollViews:picker];
return picker;
}
// ...
RCT_EXPORT_VIEW_PROPERTY(onScrollChange, RCTBubblingEventBlock)
// ...
-(void)setDelegateForScrollViews:(UIView*)view
{
if([view isKindOfClass:[UIScrollView class]]){
UIScrollView* scroll_view = (UIScrollView*) view;
RCTLogInfo(@"DEBUG setting a delegate on SV");
scroll_view.delegate = self;
}
else {
for(UIView *sub_view in [view subviews]){
[self setDelegateForScrollViews:sub_view];
}
}
}
// UIScrollViewDelegate methods
- (void)scrollViewWillBeginDragging:(UIScrollView *)scrollView {
RCTLogInfo(@"DEBUG scrollViewWillBeginDragging");
((RCTPicker*)self.view).onScrollChange(@{ @"state": [NSNumber numberWithBool:YES] });
}
- (void)scrollViewDidEndDragging:(UIScrollView *)scrollView
willDecelerate:(BOOL)decelerate {
RCTLogInfo(@"DEBUG scrollViewDidEndDragging");
((RCTPicker*)self.view).onScrollChange(@{ @"state": [NSNumber numberWithBool:NO] });
}
- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView {
RCTLogInfo(@"DEBUG scrollViewDidEndDecelerating");
// TODO
}
- (void)scrollViewDidEndScrollingAnimation:(UIScrollView *)scrollView {
RCTLogInfo(@"DEBUG scrollViewDidEndScrollingAnimation");
}
@end
But the UIScrollView Delegate methods are never raised when I scroll the picker :(...
Anyone any idea?