2015-03-23 20:28:42 +00:00
|
|
|
/**
|
|
|
|
* Copyright (c) 2015-present, Facebook, Inc.
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* This source code is licensed under the BSD-style license found in the
|
|
|
|
* LICENSE file in the root directory of this source tree. An additional grant
|
|
|
|
* of patent rights can be found in the PATENTS file in the same directory.
|
|
|
|
*/
|
2015-02-20 04:10:52 +00:00
|
|
|
|
|
|
|
#import "RCTScrollViewManager.h"
|
|
|
|
|
2015-03-06 00:36:41 +00:00
|
|
|
#import "RCTBridge.h"
|
2015-02-20 04:10:52 +00:00
|
|
|
#import "RCTScrollView.h"
|
2015-03-11 02:03:59 +00:00
|
|
|
#import "RCTSparseArray.h"
|
|
|
|
#import "RCTUIManager.h"
|
2015-02-20 04:10:52 +00:00
|
|
|
|
2015-07-07 14:38:24 +00:00
|
|
|
@interface RCTScrollView (Private)
|
2015-08-24 10:14:33 +00:00
|
|
|
|
2015-07-07 14:38:24 +00:00
|
|
|
- (NSArray *)calculateChildFramesData;
|
2015-08-24 10:14:33 +00:00
|
|
|
|
2015-07-07 14:38:24 +00:00
|
|
|
@end
|
|
|
|
|
2015-06-05 15:46:17 +00:00
|
|
|
@implementation RCTConvert (UIScrollView)
|
|
|
|
|
|
|
|
RCT_ENUM_CONVERTER(UIScrollViewKeyboardDismissMode, (@{
|
|
|
|
@"none": @(UIScrollViewKeyboardDismissModeNone),
|
|
|
|
@"on-drag": @(UIScrollViewKeyboardDismissModeOnDrag),
|
|
|
|
@"interactive": @(UIScrollViewKeyboardDismissModeInteractive),
|
|
|
|
// Backwards compatibility
|
|
|
|
@"onDrag": @(UIScrollViewKeyboardDismissModeOnDrag),
|
|
|
|
}), UIScrollViewKeyboardDismissModeNone, integerValue)
|
|
|
|
|
|
|
|
@end
|
|
|
|
|
2015-02-20 04:10:52 +00:00
|
|
|
@implementation RCTScrollViewManager
|
|
|
|
|
2015-04-08 12:42:43 +00:00
|
|
|
RCT_EXPORT_MODULE()
|
|
|
|
|
2015-02-20 04:10:52 +00:00
|
|
|
- (UIView *)view
|
|
|
|
{
|
2015-03-06 00:36:41 +00:00
|
|
|
return [[RCTScrollView alloc] initWithEventDispatcher:self.bridge.eventDispatcher];
|
2015-02-20 04:10:52 +00:00
|
|
|
}
|
|
|
|
|
2015-03-26 04:29:28 +00:00
|
|
|
RCT_EXPORT_VIEW_PROPERTY(alwaysBounceHorizontal, BOOL)
|
|
|
|
RCT_EXPORT_VIEW_PROPERTY(alwaysBounceVertical, BOOL)
|
|
|
|
RCT_EXPORT_VIEW_PROPERTY(bounces, BOOL)
|
|
|
|
RCT_EXPORT_VIEW_PROPERTY(bouncesZoom, BOOL)
|
|
|
|
RCT_EXPORT_VIEW_PROPERTY(canCancelContentTouches, BOOL)
|
|
|
|
RCT_EXPORT_VIEW_PROPERTY(centerContent, BOOL)
|
|
|
|
RCT_EXPORT_VIEW_PROPERTY(automaticallyAdjustContentInsets, BOOL)
|
|
|
|
RCT_EXPORT_VIEW_PROPERTY(decelerationRate, CGFloat)
|
|
|
|
RCT_EXPORT_VIEW_PROPERTY(directionalLockEnabled, BOOL)
|
|
|
|
RCT_EXPORT_VIEW_PROPERTY(keyboardDismissMode, UIScrollViewKeyboardDismissMode)
|
|
|
|
RCT_EXPORT_VIEW_PROPERTY(maximumZoomScale, CGFloat)
|
|
|
|
RCT_EXPORT_VIEW_PROPERTY(minimumZoomScale, CGFloat)
|
|
|
|
RCT_EXPORT_VIEW_PROPERTY(pagingEnabled, BOOL)
|
|
|
|
RCT_EXPORT_VIEW_PROPERTY(scrollEnabled, BOOL)
|
|
|
|
RCT_EXPORT_VIEW_PROPERTY(scrollsToTop, BOOL)
|
|
|
|
RCT_EXPORT_VIEW_PROPERTY(showsHorizontalScrollIndicator, BOOL)
|
|
|
|
RCT_EXPORT_VIEW_PROPERTY(showsVerticalScrollIndicator, BOOL)
|
2015-05-06 17:46:45 +00:00
|
|
|
RCT_EXPORT_VIEW_PROPERTY(stickyHeaderIndices, NSIndexSet)
|
2015-03-30 11:58:02 +00:00
|
|
|
RCT_EXPORT_VIEW_PROPERTY(scrollEventThrottle, NSTimeInterval)
|
|
|
|
RCT_EXPORT_VIEW_PROPERTY(zoomScale, CGFloat)
|
|
|
|
RCT_EXPORT_VIEW_PROPERTY(contentInset, UIEdgeInsets)
|
|
|
|
RCT_EXPORT_VIEW_PROPERTY(scrollIndicatorInsets, UIEdgeInsets)
|
2015-09-23 18:43:57 +00:00
|
|
|
RCT_EXPORT_VIEW_PROPERTY(snapToInterval, int)
|
|
|
|
RCT_EXPORT_VIEW_PROPERTY(snapToAlignment, NSString)
|
2015-03-30 11:58:02 +00:00
|
|
|
RCT_REMAP_VIEW_PROPERTY(contentOffset, scrollView.contentOffset, CGPoint)
|
|
|
|
|
2015-03-01 23:33:55 +00:00
|
|
|
- (NSDictionary *)constantsToExport
|
2015-02-20 04:10:52 +00:00
|
|
|
{
|
2015-03-01 23:33:55 +00:00
|
|
|
return @{
|
2015-06-05 15:46:17 +00:00
|
|
|
// TODO: unused - remove these?
|
2015-02-20 04:10:52 +00:00
|
|
|
@"DecelerationRate": @{
|
2015-06-05 15:46:17 +00:00
|
|
|
@"normal": @(UIScrollViewDecelerationRateNormal),
|
|
|
|
@"fast": @(UIScrollViewDecelerationRateFast),
|
2015-02-20 04:10:52 +00:00
|
|
|
},
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2015-07-31 13:55:47 +00:00
|
|
|
RCT_EXPORT_METHOD(getContentSize:(nonnull NSNumber *)reactTag
|
2015-04-08 15:52:48 +00:00
|
|
|
callback:(RCTResponseSenderBlock)callback)
|
2015-03-11 02:03:59 +00:00
|
|
|
{
|
2015-06-15 14:53:45 +00:00
|
|
|
[self.bridge.uiManager addUIBlock:^(__unused RCTUIManager *uiManager, RCTSparseArray *viewRegistry) {
|
2015-03-11 02:03:59 +00:00
|
|
|
|
|
|
|
UIView *view = viewRegistry[reactTag];
|
|
|
|
if (!view) {
|
2015-04-07 14:36:26 +00:00
|
|
|
RCTLogError(@"Cannot find view with tag #%@", reactTag);
|
2015-03-11 02:03:59 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-03-22 20:54:43 +00:00
|
|
|
CGSize size = ((RCTScrollView *)view).scrollView.contentSize;
|
2015-03-11 02:03:59 +00:00
|
|
|
callback(@[@{
|
|
|
|
@"width" : @(size.width),
|
|
|
|
@"height" : @(size.height)
|
|
|
|
}]);
|
|
|
|
}];
|
|
|
|
}
|
|
|
|
|
2015-07-31 13:55:47 +00:00
|
|
|
RCT_EXPORT_METHOD(calculateChildFrames:(nonnull NSNumber *)reactTag
|
2015-07-07 14:38:24 +00:00
|
|
|
callback:(RCTResponseSenderBlock)callback)
|
|
|
|
{
|
|
|
|
[self.bridge.uiManager addUIBlock:^(__unused RCTUIManager *uiManager, RCTSparseArray *viewRegistry) {
|
|
|
|
|
|
|
|
UIView *view = viewRegistry[reactTag];
|
|
|
|
if (!view) {
|
|
|
|
RCTLogError(@"Cannot find view with tag #%@", reactTag);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
NSArray *childFrames = [((RCTScrollView *)view) calculateChildFramesData];
|
|
|
|
if (childFrames) {
|
|
|
|
callback(@[childFrames]);
|
|
|
|
}
|
|
|
|
}];
|
|
|
|
}
|
|
|
|
|
2015-08-11 13:37:12 +00:00
|
|
|
- (NSArray *)customDirectEventTypes
|
|
|
|
{
|
|
|
|
return @[
|
|
|
|
@"scrollBeginDrag",
|
|
|
|
@"scroll",
|
|
|
|
@"scrollEndDrag",
|
|
|
|
@"scrollAnimationEnd",
|
|
|
|
@"momentumScrollBegin",
|
|
|
|
@"momentumScrollEnd",
|
|
|
|
];
|
|
|
|
}
|
|
|
|
|
2015-02-20 04:10:52 +00:00
|
|
|
@end
|