diff --git a/.github/FUNDING.yml b/.github/FUNDING.yml new file mode 100644 index 0000000..f92f7f3 --- /dev/null +++ b/.github/FUNDING.yml @@ -0,0 +1,3 @@ +# These are supported funding model platforms + +github: [mbender74] diff --git a/README.md b/README.md index 5d63769..b962e2b 100755 --- a/README.md +++ b/README.md @@ -15,7 +15,7 @@ manually hide the controller, per exaple if to did any action in the content vie ### `selectedDetentIdentifier` return STRING - selectedDetentIdentifier (medium,large or none) ### `changeCurrentDetent(STRING)` -change the selectedDetentIdentifier animated ('large' or 'medium') **on 'nonSystemSheet:true' only** +change the selectedDetentIdentifier animated ('large' or 'medium') **on 'nonSystemSheet:false' only** (iOS15+) ## Events @@ -76,6 +76,27 @@ when your contentView is not a scrollable view, then this activates scrolling if **ATTENTION**: when you put a tableView, scrollView or listView inside your contentView this property disables scrolling in the contentView in favour of the bottomSheetScrollView +### `nonSystemSheetAutomaticStartPositionFromContentViewHeight:bool` +when this property is "**true**" the nonSystemSheet opens in the height of the contentView, **all detents are disabled**, + +only the real height is active, + +"**startDetent**" property **will be ignored**, also the "detents" property are ignored -- + +if you want an undimmed background, then you need to set property "**largestUndimmedDetentIdentifier**" to "large" + +if NOT set defaults to false + +### `nonSystemSheetSmallHeight:integer` +(optional) when set, the small detent is set to this height + +### `nonSystemSheetMediumHeight:integer` +(optional) when set, the medium detent is set to this height + +### `nonSystemSheetLargeHeight:integer` +(optional) when set, the large detent is set to this height + + ## Example ```js diff --git a/ios/Classes/BottomSheetViewController.h b/ios/Classes/BottomSheetViewController.h index f59db34..0d78042 100644 --- a/ios/Classes/BottomSheetViewController.h +++ b/ios/Classes/BottomSheetViewController.h @@ -26,18 +26,20 @@ static CGFloat maxPosition = 0; static State minState = partial; static CGFloat minPosition = 0; static UIEdgeInsets insets; +static UIEdgeInsets scrollBarinsets; static bool panEnabled = YES; static bool panInit = NO; static bool panFromScrollView = NO; - +static CGFloat width = 0; +static CGFloat height = 0; +static CGRect customViewRect; static bool fullPositon = YES; static bool mediumPosition = YES; static bool smallPosition = YES; static CGFloat lastScrollViewOffsetY = 0; static CGFloat newSrollViewOffsetY = 0; static CGFloat lastTranslation = 0; - - +static CGFloat yPosition = 0; static NSDictionary *userDetents; static CGFloat fullViewYPosition = 0; static CGFloat partialViewYPosition = 0; @@ -49,9 +51,13 @@ static UIColor *dimmedViewBackgroundColor = nil; static NSString *largestUndimmedDetent = nil; static NSString *startDetent = nil; static NSString *detentString = nil; +static Director director = up; @interface BottomSheetViewController : UIViewController @property (assign, nonatomic) State lastStatus; @property (assign, nonatomic) NSString *selectedDetentIdentifier; +@property (assign, nonatomic) CGFloat fullViewYPosition; +@property (assign, nonatomic) CGFloat partialViewYPosition; +@property (assign, nonatomic) CGFloat expandedViewYPosition; - (id)proxyOfBottomSheetController; - (void)setProxyOfBottomSheetController:(id)args; @@ -64,9 +70,10 @@ static NSString *detentString = nil; - (UIPanGestureRecognizer *)panRecognizer; - (void)panRecognizerInit:(bool)enabled; - (void)panFromScrollView:(bool)enabled; - +- (void)changeInsets:(UIView *)view; - (void)scrollView:(UIScrollView*)scrollview; - (void)lastContentOffsetY:(CGFloat)contentOffsetY; +- (void)setupData; @end NS_ASSUME_NONNULL_END diff --git a/ios/Classes/BottomSheetViewController.m b/ios/Classes/BottomSheetViewController.m index cfa1a51..9f06e96 100644 --- a/ios/Classes/BottomSheetViewController.m +++ b/ios/Classes/BottomSheetViewController.m @@ -22,6 +22,9 @@ @implementation BottomSheetViewController TiBottomsheetcontrollerProxy *myParentProxy; UIScrollView *customSheetScrollView; +UIView *customView; +CGRect windowRect; + UIPanGestureRecognizer *thisGesture; UIEdgeInsets safeAreaInset; @@ -40,48 +43,100 @@ -(void)setProxyOfBottomSheetController:(id)args - (void)viewDidLoad { [super viewDidLoad]; - // Do any additional setup after loading the view. + + fullViewYPosition = 100; + partialViewYPosition = [UIScreen mainScreen].bounds.size.height - 130; + expandedViewYPosition = ceilf([UIScreen mainScreen].bounds.size.height / 2); + + self.fullViewYPosition = fullViewYPosition; + self.partialViewYPosition = partialViewYPosition; + self.expandedViewYPosition = expandedViewYPosition; + [self setupData]; [self setupGestureEvent]; - } - (void)viewDidAppear:(BOOL)animated { + [super viewDidAppear:animated]; __weak __typeof(self)weakSelf = self; - dispatch_async(dispatch_get_main_queue(), ^{ - - [UIView animateWithDuration:0.25 - delay:0.0 - options:UIViewAnimationOptionCurveEaseOut - animations:^{ - [myParentProxy backgroundView].backgroundColor = viewBackgroundColor; - //weakSelf.parentViewController.view.backgroundColor = viewBackgroundColor; - [weakSelf moveView:weakSelf.lastStatus]; - } completion:^(BOOL finished) { - }]; - }); -} + customView = [myParentProxy contentViewOfSheet]; + windowRect = customView.frame; + director = up; + + [UIView animateWithDuration:0.35 delay:0 usingSpringWithDamping:1 initialSpringVelocity:1 options:UIViewAnimationOptionCurveEaseOut animations:^{ + [myParentProxy backgroundView].backgroundColor = viewBackgroundColor; + [weakSelf moveView:weakSelf.lastStatus]; + } completion:^(BOOL finished) { + + CGFloat startY = fullViewYPosition; -#pragma mark - + if (self.lastStatus == partial) { + startY = partialViewYPosition; + } else if (self.lastStatus == expanded) { + startY = expandedViewYPosition; + } + customView = [myParentProxy contentViewOfSheet]; + windowRect = customView.frame; + + if (customSheetScrollView){ + customViewRect = customSheetScrollView.frame; + customViewRect.size.height = self.view.frame.size.height - startY; + customSheetScrollView.frame = customViewRect; + customView.frame = windowRect; + + if (myParentProxy.fixedHeight == NO){ + [myParentProxy.viewProxy reposition]; + [myParentProxy.viewProxy layoutChildrenIfNeeded]; + } + } + else { + if (myParentProxy.fixedHeight == NO){ + customViewRect = customView.frame; + customViewRect.size.height = self.view.frame.size.height - startY; + customView.frame = customViewRect; + [myParentProxy.viewProxy reposition]; + [myParentProxy.viewProxy layoutChildrenIfNeeded]; + } + } + }]; + [myParentProxy fireEvent:@"opened" withObject:nil]; +} + +#pragma mark - - (void)setupData { dismissModeOfSheet = NO; backgroundViewHidden = YES; viewBackgroundColor = [UIColor clearColor]; dimmedViewBackgroundColor = [[TiUtils colorValue:@"#22000000"] _color]; - fullViewYPosition = 100; - partialViewYPosition = [UIScreen mainScreen].bounds.size.height - 130; - expandedViewYPosition = ceilf([UIScreen mainScreen].bounds.size.height / 2); + + + if ([myParentProxy valueForKey:@"nonSystemSheetSmallHeight"]){ + self.partialViewYPosition = [UIScreen mainScreen].bounds.size.height - [TiUtils intValue:[myParentProxy valueForKey:@"nonSystemSheetSmallHeight"]]; + } + if ([myParentProxy valueForKey:@"nonSystemSheetMediumHeight"]){ + self.expandedViewYPosition = [UIScreen mainScreen].bounds.size.height - [TiUtils intValue:[myParentProxy valueForKey:@"nonSystemSheetMediumHeight"]]; + + } + if ([myParentProxy valueForKey:@"nonSystemSheetLargeHeight"]){ + self.fullViewYPosition = [UIScreen mainScreen].bounds.size.height - [TiUtils intValue:[myParentProxy valueForKey:@"nonSystemSheetLargeHeight"]]; + } + + fullViewYPosition = self.fullViewYPosition; + partialViewYPosition = self.partialViewYPosition; + expandedViewYPosition = self.expandedViewYPosition; + + width = self.view.frame.size.width; + height = self.view.frame.size.height; safeAreaInset = UIEdgeInsetsZero; UIViewController *topContainerController = [[[TiApp app] controller] topContainerController]; - safeAreaInset = [[topContainerController hostingView] safeAreaInsets]; @@ -167,6 +222,23 @@ - (void)setupData { } } + + if ([myParentProxy nonSystemSheetAutomaticStartPositionFromContentViewHeight] == YES){ + CGFloat realHeight; + realHeight = [myParentProxy realContentHeight] + safeAreaInset.bottom; + + fullViewYPosition = [UIScreen mainScreen].bounds.size.height - realHeight; + + maxPosition = fullViewYPosition; + minPosition = fullViewYPosition; + maxState = full; + minState = full; + mediumPosition = NO; + smallPosition = NO; + fullPositon = YES; + startDetent = @"large"; + } + if ([myParentProxy valueForKey:@"largestUndimmedDetentIdentifier"]){ largestUndimmedDetent = [TiUtils stringValue:[myParentProxy valueForKey:@"largestUndimmedDetentIdentifier"]]; } @@ -175,9 +247,6 @@ - (void)setupData { } - - - if ([startDetent isEqual: @"small"]){ if ([TiUtils boolValue:[userDetents valueForKey:@"small"] def:YES]){ self.lastStatus = partial; @@ -236,32 +305,80 @@ - (void)setupData { } } [myParentProxy backgroundView].hidden = backgroundViewHidden; +} + +#pragma mark - +- (void)changeInsets:(UIView *)view +{ + CGFloat bottomIntent = safeAreaInset.bottom; + CGFloat topInset; + CGFloat diffPos = (yPosition-(yPosition-maxPosition)); + - if (customSheetScrollView){ - CGFloat height = self.view.frame.size.height; - CGFloat bottomIntent = safeAreaInset.bottom; - CGFloat topInset = customSheetScrollView.contentInset.top; + if (self.lastStatus == partial) { + bottomIntent = ((height)-130)+safeAreaInset.bottom; + } + else if (self.lastStatus == expanded) { + bottomIntent = ((height/2))+safeAreaInset.bottom; + } + else { + bottomIntent = safeAreaInset.bottom + 100; + } + + if ([view respondsToSelector:@selector(setScrollEnabled:)]){ - if (self.lastStatus == partial) { - bottomIntent = (((height) - 136) - bottomIntent); - } - else if (self.lastStatus == expanded) { - bottomIntent = (((height)/2) - bottomIntent) - 6; - } - else { - bottomIntent = bottomIntent + 24; - } - insets = UIEdgeInsetsMake(topInset, 0, bottomIntent, 0); - [customSheetScrollView setContentInset:insets]; - [customSheetScrollView setScrollIndicatorInsets:insets]; + if ([view isKindOfClass:[UITableView class]]){ + UITableView *thisTableView = (UITableView *)view; + topInset = thisTableView.contentInset.top; + + scrollBarinsets = UIEdgeInsetsMake(topInset + 20, 0, bottomIntent - 20, 0); + insets = UIEdgeInsetsMake(topInset, 0, bottomIntent - 20, 0); + [thisTableView setContentInset:insets]; + [thisTableView setScrollIndicatorInsets:scrollBarinsets]; + } + else if ([view isKindOfClass:[UIScrollView class]]){ + UIScrollView *thisTableView = (UIScrollView *)view; + topInset = thisTableView.contentInset.top; + insets = UIEdgeInsetsMake(topInset, 0, bottomIntent - 20, 0); + scrollBarinsets = UIEdgeInsetsMake(topInset + 20, 0, bottomIntent, 0); + [thisTableView setContentInset:insets]; + [thisTableView setScrollIndicatorInsets:scrollBarinsets]; + } + else { + } } + else { + for (UIView *eachView in view.subviews) { - + if ([eachView respondsToSelector:@selector(setScrollEnabled:)]){ + + if ([eachView isKindOfClass:[UITableView class]]){ + UITableView *thisTableView = (UITableView *)eachView; + topInset = thisTableView.contentInset.top; + insets = UIEdgeInsetsMake(topInset, 0, bottomIntent, 0); + scrollBarinsets = UIEdgeInsetsMake(topInset + 20, 0, bottomIntent, 0); + + [thisTableView setContentInset:insets]; + [thisTableView setScrollIndicatorInsets:scrollBarinsets]; + } + else if ([eachView isKindOfClass:[UIScrollView class]]){ + UIScrollView *thisTableView = (UIScrollView *)eachView; + topInset = thisTableView.contentInset.top; + insets = UIEdgeInsetsMake(topInset, 0, bottomIntent - 20, 0); + scrollBarinsets = UIEdgeInsetsMake(topInset + 20, 0, bottomIntent, 0); + + [thisTableView setContentInset:insets]; + [thisTableView setScrollIndicatorInsets:scrollBarinsets]; + } + else { + } + } + [self changeInsets:eachView]; + } + } } -#pragma mark - - - (State)state { return self.lastStatus; } @@ -282,7 +399,6 @@ - (UIPanGestureRecognizer *)panRecognizer { return thisGesture; } - - (void)setupGestureEvent { UIPanGestureRecognizer *gesture = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(panGesture:)]; [self.view addGestureRecognizer:gesture]; @@ -291,52 +407,25 @@ - (void)setupGestureEvent { } - (void)moveView:(State)state { - CGFloat yPosition = fullViewYPosition; - const CGFloat width = self.view.frame.size.width; - const CGFloat height = self.view.frame.size.height; - CGFloat bottomIntent = safeAreaInset.bottom; + yPosition = fullViewYPosition; if (dismissModeOfSheet == NO){ if (state == partial) { yPosition = partialViewYPosition; - bottomIntent = (((height) - 136) - bottomIntent); - } else if (state == expanded) { yPosition = expandedViewYPosition; - bottomIntent = (((height)/2) - bottomIntent) - 6; } else { - // bottomIntent = 130; - // bottomIntent = bottomIntent - 100; - // bottomIntent = bottomIntent + 24; - bottomIntent = bottomIntent + 24; } } else { yPosition = [UIScreen mainScreen].bounds.size.height; - // bottomIntent = bottomIntent - 100; - // bottomIntent = bottomIntent + 24; - bottomIntent = bottomIntent + 24; - } CGRect rect = CGRectMake(0 , yPosition, width, height); - - - // NSLog(@"before insets %f",bottomIntent); - // NSLog(@"customSheetScrollView %@",customSheetScrollView); - - CGFloat topInset = customSheetScrollView.contentInset.top; - - if (customSheetScrollView){ - // NSLog(@"intents %f",bottomIntent); - - insets = UIEdgeInsetsMake(topInset, 0, bottomIntent, 0); - [customSheetScrollView setContentInset:insets]; - [customSheetScrollView setScrollIndicatorInsets:insets]; - } - + customViewRect.size.height = height - yPosition; + self.view.frame = rect; } @@ -347,24 +436,45 @@ - (void)moveViewWithGesture:(UIPanGestureRecognizer *)recognizer { panInit = NO; translation.y = 0; } - - // NSLog(@"sheet translation %f", translation.y); - -// if (translation.y > 1){ -// translation.y = 1; -// } - const CGFloat minY = self.view.frame.origin.y; dismissModeOfSheet = NO; - - if ((minY + translation.y >= maxPosition)) { - const CGFloat width = self.view.frame.size.width; - const CGFloat height = self.view.frame.size.height; - const CGRect rect = CGRectMake(0 , minY + translation.y, width, height); + CGFloat newY = minY + translation.y; + + if ((newY >= maxPosition)) { + width = self.view.frame.size.width; + height = self.view.frame.size.height; + const CGRect rect = CGRectMake(0 , newY, width, height); self.view.frame = rect; + + if (recognizer.state != UIGestureRecognizerStateEnded) { + customViewRect.size.height = height - newY; + + if (customSheetScrollView){ + customSheetScrollView.frame = customViewRect; + customView.frame = windowRect; + + if (myParentProxy.fixedHeight == NO){ + [myParentProxy.viewProxy reposition]; + + [myParentProxy.viewProxy layoutChildren:YES]; + [myParentProxy.viewProxy willChangeSize]; + } + } + else { + if (myParentProxy.fixedHeight == NO){ + customView.frame = customViewRect; + + [myParentProxy.viewProxy reposition]; + + [myParentProxy.viewProxy layoutChildren:YES]; + [myParentProxy.viewProxy willChangeSize]; + } + } + + } [recognizer setTranslation:CGPointZero inView:self.view]; - if (minY + translation.y > minPosition) { + if (newY > minPosition) { dismissModeOfSheet = YES; } else { @@ -373,11 +483,13 @@ - (void)moveViewWithGesture:(UIPanGestureRecognizer *)recognizer { } } + + + - (void)roundViews { self.view.clipsToBounds = NO; } - - (void)scrollView:(UIScrollView*)scrollview { customSheetScrollView = scrollview; } @@ -389,83 +501,6 @@ - (void)panGesture:(UIPanGestureRecognizer *)recognizer { CGPoint translation = [recognizer translationInView:self.view]; -// NSLog(@"panEnabled %d",panEnabled); -// -// NSLog(@"translation %f",translation.y); -// NSLog(@"lastTranslation %f",lastTranslation); -// -// NSLog(@"newSrollViewOffsetY %f",newSrollViewOffsetY); -// NSLog(@"lastScrollViewOffsetY %f",lastScrollViewOffsetY); -// NSLog(@"customSheetScrollView.isDragging %d",customSheetScrollView.isDragging); -// -// -// dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{ -// -// }); - - - if (customSheetScrollView != nil){ - - - if (panFromScrollView == YES){ - // NSLog(@"---------------- panFromScrollView"); - - if (panEnabled == YES && customSheetScrollView.isDragging == NO){ - // NSLog(@"---------------- panFromScrollView SKIP"); - - return; - } - - } - else { - // NSLog(@"-------------- NO panFromScrollView"); - - } - - if (lastScrollViewOffsetY != newSrollViewOffsetY && customSheetScrollView.isDragging != NO){ - // NSLog(@"lastScrollViewOffsetY != newSrollViewOffsetY && dragging != NO"); - lastScrollViewOffsetY = newSrollViewOffsetY; - lastTranslation = translation.y; - } - else { - - if ((panEnabled == YES && lastTranslation == newSrollViewOffsetY) || (panEnabled == YES && translation.y == 0)){ - - if ((panEnabled == YES && lastScrollViewOffsetY == newSrollViewOffsetY)){ - lastTranslation = translation.y; - lastScrollViewOffsetY = newSrollViewOffsetY; - // NSLog(@"++++++++++++++ NO SKIP"); - - } - else { - if (customSheetScrollView.isDragging == NO){ - // NSLog(@"SKIP"); - lastTranslation = translation.y; - lastScrollViewOffsetY = newSrollViewOffsetY; - return; - } - // NSLog(@"++++++++++++++ NO SKIP AFTER"); - - lastTranslation = translation.y; - lastScrollViewOffsetY = newSrollViewOffsetY; - } - } - - lastTranslation = translation.y; - lastScrollViewOffsetY = newSrollViewOffsetY; - } - if (panEnabled == NO){ - lastTranslation = translation.y; - - lastScrollViewOffsetY = newSrollViewOffsetY; - return; - } - lastTranslation = translation.y; - - lastScrollViewOffsetY = newSrollViewOffsetY; - } - - [self moveViewWithGesture:recognizer]; if (recognizer.state != UIGestureRecognizerStateEnded) { @@ -474,19 +509,17 @@ - (void)panGesture:(UIPanGestureRecognizer *)recognizer { __weak __typeof(self)weakSelf = self; - if (dismissModeOfSheet == YES){ [myParentProxy sendEvent:@"dismiss"]; return; } else { - // dispatch_async(dispatch_get_main_queue(), ^{ - [UIView animateKeyframesWithDuration:0.25 + [UIView animateKeyframesWithDuration:0.3 delay:0.0 - options:UIViewKeyframeAnimationOptionAllowUserInteraction + options:UIViewKeyframeAnimationOptionAllowUserInteraction | UIViewAnimationOptionCurveEaseInOut animations:^{ - const Director director = [recognizer velocityInView:weakSelf.view].y >= 0 ? down: up; + director = [recognizer velocityInView:weakSelf.view].y >= 0 ? down: up; State state = weakSelf.lastStatus; if (weakSelf.lastStatus == partial && director == up) { @@ -567,7 +600,33 @@ - (void)panGesture:(UIPanGestureRecognizer *)recognizer { } weakSelf.lastStatus = state; + + [weakSelf moveView:state]; + if (director == up){ + if (customSheetScrollView){ + customSheetScrollView.frame = customViewRect; + customView.frame = windowRect; + + if (myParentProxy.fixedHeight == NO){ + [myParentProxy.viewProxy reposition]; + + [myParentProxy.viewProxy layoutChildren:YES]; + [myParentProxy.viewProxy willChangeSize]; + } + } + else { + + if (myParentProxy.fixedHeight == NO){ + customView.frame = customViewRect; + + [myParentProxy.viewProxy reposition]; + + [myParentProxy.viewProxy layoutChildren:YES]; + [myParentProxy.viewProxy willChangeSize]; + } + } + } if (self.lastStatus == expanded){ @@ -632,22 +691,19 @@ - (void)panGesture:(UIPanGestureRecognizer *)recognizer { [myParentProxy backgroundView].hidden = backgroundViewHidden; } - [UIView animateWithDuration:0.25 - delay:0.0 - options:UIViewAnimationOptionCurveEaseOut - animations:^{ - [myParentProxy backgroundView].backgroundColor = viewBackgroundColor; + + [UIView animateWithDuration:0.3 delay:0 options:UIViewAnimationOptionCurveEaseInOut animations:^{ + [myParentProxy backgroundView].backgroundColor = viewBackgroundColor; } completion:^(BOOL finished) { if (backgroundViewHidden == YES){ [myParentProxy backgroundView].hidden = backgroundViewHidden; } - if (customSheetScrollView != nil){ - customSheetScrollView.panGestureRecognizer.enabled = YES; - } - }]; + + + }]; + }); - } id detentID = detentString; @@ -657,13 +713,35 @@ - (void)panGesture:(UIPanGestureRecognizer *)recognizer { } completion:^(BOOL finished) { - - + if (director == down){ + if (customSheetScrollView){ + customSheetScrollView.frame = customViewRect; + customView.frame = windowRect; + + if (myParentProxy.fixedHeight == NO){ + [myParentProxy.viewProxy reposition]; + + [myParentProxy.viewProxy willChangeSize]; + [myParentProxy.viewProxy layoutChildren:YES]; + + } + } + else { + + if (myParentProxy.fixedHeight == NO){ + customView.frame = customViewRect; + + [myParentProxy.viewProxy reposition]; + + [myParentProxy.viewProxy willChangeSize]; + [myParentProxy.viewProxy layoutChildren:YES]; + } + } + + + } }]; - // }); } - - } @end diff --git a/ios/Classes/TiBottomsheetcontrollerProxy.h b/ios/Classes/TiBottomsheetcontrollerProxy.h index 8e71abe..7dedd78 100755 --- a/ios/Classes/TiBottomsheetcontrollerProxy.h +++ b/ios/Classes/TiBottomsheetcontrollerProxy.h @@ -7,6 +7,9 @@ * WARNING: This is generated code. Modify at your own risk and without support. */ #define USE_TI_UINAVIGATIONWINDOW +#define USE_TI_UISCROLLVIEW // Enable access to the core class +#define USE_TI_UITABLEVIEW // Enable access to the core class +#define USE_TI_UILISTVIEW #import #import @@ -14,6 +17,14 @@ #import #import "TiUINavigationWindowProxy.h" #import "TiUINavigationWindowInternal.h" +#import "TiWindowProxy+Addons.h" +#import "TiUIScrollViewProxy.h" +#import "TiUITableViewProxy.h" +#import "TiUIListViewProxy.h" +#import "TiUIScrollView.h" +#import "TiUITableView.h" +#import "TiUIListView.h" +#import @interface ContentScrollView : UIScrollView @@ -23,15 +34,19 @@ @interface TiBottomsheetcontrollerProxy : TiProxy { +@private pthread_rwlock_t listenerLockSheet; NSMutableDictionary *listenersSheet; UIEdgeInsets insets; UIView *containerView; + UIView *contentViewOfSheet; ContentScrollView *scrollView; BOOL nonSystemSheetShouldScroll; + BOOL nonSystemSheetAutomaticStartPositionFromContentViewHeight; BOOL eventFired; BOOL useNavController; BOOL defaultsToNonSystemSheet; + BOOL contentViewScrollingDisabled; CGSize TiBottomSheetContentSize; UIViewController *viewController; TiUINavigationWindowProxy *centerProxy; @@ -40,11 +55,13 @@ NSString *detentStatus; NSString *lastDetentStatus; UIView *backgroundView; - @private + CGFloat realContentHeight; + CGFloat scrollableContentHeight; + UIEdgeInsets bottomSheetSafeAreaInset; TiViewProxy *contentViewProxy; TiViewProxy *closeButtonProxy; BOOL animated; - BOOL popoverInitialized; + BOOL bottomSheetInitialized; BOOL isDismissing; NSCondition *bottomSheetclosingCondition; TiDimension poWidth; @@ -53,14 +70,25 @@ TiDimension poBHeight; BOOL deviceRotated; } + + +@property (assign, nonatomic) BOOL fixedHeight; +@property (assign, nonatomic) BOOL insetsDone; + +@property (assign, nonatomic) TiViewProxy *viewProxy; + @property(nonatomic, copy) NSArray * _Nullable detents; @property(nonatomic, copy, nullable) UISheetPresentationControllerDetentIdentifier largestUndimmedDetentIdentifier; - (void)sendEvent:(id)args; - (UIView*)backgroundView; +- (UIView*)containerView; +- (CGFloat)realContentHeight; +- (CGFloat)scrollableContentHeight; +- (BOOL)nonSystemSheetAutomaticStartPositionFromContentViewHeight; - (UIScrollView*)scrollView; -- (TiBottomsheetcontrollerProxy*)bottomSheet; - (void)bottomSheetModule:(id)args; - +- (BOOL)nonSystemSheetShouldScroll; +- (UIView*)contentViewOfSheet; @end @interface myViewController : UIViewController diff --git a/ios/Classes/TiBottomsheetcontrollerProxy.m b/ios/Classes/TiBottomsheetcontrollerProxy.m index 7ffd234..a6b9286 100755 --- a/ios/Classes/TiBottomsheetcontrollerProxy.m +++ b/ios/Classes/TiBottomsheetcontrollerProxy.m @@ -17,6 +17,7 @@ #import #import "BottomSheetViewController.h" #import "TiBottomsheetcontrollerModule.h" +#import TiBottomsheetcontrollerProxy *currentTiBottomSheet; BottomSheetViewController *customBottomSheet; @@ -35,9 +36,13 @@ - (id)init poHeight = TiDimensionUndefined; poBWidth = TiDimensionUndefined; poBHeight = TiDimensionUndefined; - // NSLog(@"self %@",self); nonSystemSheetShouldScroll = NO; defaultsToNonSystemSheet = YES; + nonSystemSheetAutomaticStartPositionFromContentViewHeight = NO; + useNavController = NO; + contentViewScrollingDisabled = NO; + UIViewController *topContainerController = [[[TiApp app] controller] topContainerController]; + bottomSheetSafeAreaInset = [[topContainerController hostingView] safeAreaInsets]; } return self; @@ -48,9 +53,9 @@ - (void)dealloc [[NSNotificationCenter defaultCenter] removeObserver:self]; [viewController.view removeObserver:self forKeyPath:@"safeAreaInsets"]; RELEASE_TO_NIL(viewController); - popoverInitialized = NO; + bottomSheetInitialized = NO; currentTiBottomSheet = nil; - + nonSystemSheetAutomaticStartPositionFromContentViewHeight = NO; RELEASE_TO_NIL(bottomSheetclosingCondition); RELEASE_TO_NIL(contentViewProxy); #if !TARGET_OS_MACCATALYST @@ -157,6 +162,18 @@ - (void)setNonSystemSheetShouldScroll:(id)value { nonSystemSheetShouldScroll = [TiUtils boolValue:value]; } +- (BOOL)nonSystemSheetShouldScroll +{ + return nonSystemSheetShouldScroll; +} + + + +- (void)setNonSystemSheetAutomaticStartPositionFromContentViewHeight:(id)value +{ + nonSystemSheetAutomaticStartPositionFromContentViewHeight = [TiUtils boolValue:value]; +} + - (void)setNonSystemSheet:(id)value { @@ -176,20 +193,16 @@ - (void)setContentView:(id)value RELEASE_TO_NIL(contentViewProxy); } contentViewProxy = [(TiViewProxy *)value retain]; - + self.viewProxy = contentViewProxy; [self replaceValue:contentViewProxy forKey:@"contentView" notification:NO]; } - (void)sendEvent:(id)args { - //NSLog(@"sendEvent"); - detentStatus = [TiUtils stringValue:args]; if ([detentStatus isEqual:@"dismiss"]){ - - // NSLog(@"sendEvent dismiss"); if (isDismissing == NO){ isDismissing = YES; [self hide:nil]; @@ -203,24 +216,10 @@ - (void)sendEvent:(id)args forKey:@"selectedDetentIdentifier"]; [self fireEvent:@"detentChange" withObject:event]; - - - - // NSLog(@"sendEvent %@",[TiUtils stringValue:args]); } if (scrollView != nil){ - // scrollView.scrollEnabled = YES; - // scrollView.userInteractionEnabled = NO; - - // scrollView.panGestureRecognizer.enabled = YES; scrollView.dismissing = NO; - // [customBottomSheet lastContentOffsetY:-1]; - // scrollView.panGestureRecognizer.enabled = YES; - [customBottomSheet panFromScrollView:NO]; - [customBottomSheet panRecognizerEnabled:YES]; - // scrollView.panGestureRecognizer.enabled = YES; - } } lastDetentStatus = detentStatus; @@ -235,23 +234,15 @@ - (void)addEventListener:(NSArray *)args NSString *type = [args objectAtIndex:0]; if (![self _hasListeners:@"closed"] && [type isEqual:@"closed"]) { - // NSLog(@"BottomSheet addEventListener"); - [super addEventListener:args]; } if (![self _hasListeners:@"opened"] && [type isEqual:@"opened"]) { - // NSLog(@"BottomSheet addEventListener"); - [super addEventListener:args]; } if (![self _hasListeners:@"dismissing"] && [type isEqual:@"dismissing"]) { - // NSLog(@"BottomSheet addEventListener"); - [super addEventListener:args]; } if (![self _hasListeners:@"detentChange"] && [type isEqual:@"detentChange"]) { - // NSLog(@"BottomSheet addEventListener"); - [super addEventListener:args]; } @@ -259,64 +250,38 @@ - (void)addEventListener:(NSArray *)args - (void)show:(id)args { - ENSURE_SINGLE_ARG_OR_NIL(args, NSDictionary); - // NSLog(@"BottomSheet show"); - - // dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.05 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{ - - // if (isDismissing == NO){ - + ENSURE_SINGLE_ARG_OR_NIL(args, NSDictionary); + if (bottomSheetInitialized == NO) { + eventFired = NO; - - if (popoverInitialized == NO) { - // NSLog(@"!popoverInitialized"); - eventFired = NO; - - if (contentViewProxy == nil) { - NSLog(@"[ERROR] BottomSheet no contentView set - Ignoring call") return; - } - - - [self rememberSelf]; - [self retain]; - - animated = [TiUtils boolValue:@"animated" properties:args def:YES]; - - - TiThreadPerformOnMainThread( - ^{ - [self initAndShowSheetController]; - isDismissing = NO; - popoverInitialized = YES; - }, - YES); - } - else { + if (contentViewProxy == nil) { + NSLog(@"[ERROR] BottomSheet no contentView set - Ignoring call") return; + } - NSLog(@"[ERROR] BottomSheet is showing. Ignoring call") return; - -// TiThreadPerformOnMainThread( -// ^{ -// [currentTiBottomSheet sendEvent:@"dismiss"]; -// }, -// YES); - - } - // } + [self rememberSelf]; + [self retain]; - // }); - + animated = [TiUtils boolValue:@"animated" properties:args def:YES]; + + TiThreadPerformOnMainThread( + ^{ + [self initAndShowSheetController]; + isDismissing = NO; + bottomSheetInitialized = YES; + }, + YES); + } + else { + NSLog(@"[ERROR] BottomSheet is showing. Ignoring call") return; + } } - (void)hide:(id)args { - //NSLog(@"BottomSheet hide"); - - if (popoverInitialized == NO) { + if (bottomSheetInitialized == NO) { NSLog(@"BottomSheet is not showing. Ignoring call") return; } - TiThreadPerformOnMainThread( ^{ @@ -326,21 +291,16 @@ - (void)hide:(id)args self->animated = [TiUtils boolValue:@"animated" properties:args def:YES]; [[self viewController] dismissViewControllerAnimated:self->animated - completion:^{ - // NSLog(@"BottomSheet closed iOS15+"); + completion:^{ if (eventFired == NO){ eventFired = YES; - - // NSLog(@"BottomSheet before closed fired"); - + if ([self _hasListeners:@"closed"]) { [self fireEvent:@"closed" withObject:nil]; } - - // NSLog(@"BottomSheet closed fired"); - + [bottomSheetModule cleanup]; - popoverInitialized = NO; + bottomSheetInitialized = NO; bottomSheet = nil; viewController = nil; @@ -349,28 +309,19 @@ - (void)hide:(id)args closeButtonView = nil; currentTiBottomSheet = nil; } - - //[self cleanup]; - }]; - + }]; } else { if (eventFired == NO){ eventFired = YES; - // NSLog(@"BottomSheet closed iOS < 15+"); [self->contentViewProxy windowWillClose]; - // - - UIColor *viewBackgroundColor = [UIColor clearColor]; - - [UIView animateWithDuration:0.25 delay:0.0 - options:UIViewAnimationOptionCurveEaseOut + options:UIViewAnimationOptionCurveEaseIn animations:^{ backgroundView.backgroundColor = viewBackgroundColor; CGFloat width = customBottomSheet.view.frame.size.width; @@ -380,12 +331,9 @@ - (void)hide:(id)args } completion:^(BOOL finished) { if (finished){ - - // NSLog(@"BottomSheet before closed fired"); - + if ([self _hasListeners:@"closed"]) { [self fireEvent:@"closed" withObject:nil]; - // NSLog(@"BottomSheet closed fired"); } if (useNavController) { @@ -396,7 +344,6 @@ - (void)hide:(id)args } [backgroundView removeFromSuperview]; [customBottomSheet.view removeFromSuperview]; - // [[TiApp app] hideModalController:viewController animated:NO]; [[NSNotificationCenter defaultCenter] removeObserver:self]; currentTiBottomSheet = nil; @@ -406,57 +353,58 @@ - (void)hide:(id)args // [viewController.view removeFromSuperview]; [bottomSheetModule cleanup]; scrollView = nil; - popoverInitialized = NO; + bottomSheetInitialized = NO; contentViewProxy = nil; customBottomSheet = nil; backgroundView = nil; viewController = nil; closeButtonView = nil; - - // [customBottomSheet willMoveToParentViewController:viewController]; - // [customBottomSheet.view removeFromSuperview]; - // [customBottomSheet removeFromParentViewController]; - - - - } - - }]; - - - } - else { - // NSLog(@"BottomSheet closed Event already fired"); } } - - // [self dealloc]; }, YES); - - - // NSLog(@"BottomSheet hide done"); +} +- (void)bottomSheetModule:(id)args +{ + bottomSheetModule = args; } -- (TiBottomsheetcontrollerProxy*)bottomSheet +- (UIView *)containerView { - return bottomSheet; + return containerView; } -- (void)bottomSheetModule:(id)args +- (CGFloat)realContentHeight { - bottomSheetModule = args; + return realContentHeight; +} +- (CGFloat)scrollableContentHeight +{ + return scrollableContentHeight; } +- (BOOL)nonSystemSheetAutomaticStartPositionFromContentViewHeight +{ + return nonSystemSheetAutomaticStartPositionFromContentViewHeight; +} + - (UIView *)backgroundView { return backgroundView; } +- (UIView *)contentViewOfSheet +{ + return contentViewOfSheet; +} + + + + - (UIScrollView *)scrollView { return scrollView; @@ -469,12 +417,10 @@ - (UIViewController *)viewController if ([contentViewProxy isKindOfClass:[TiWindowProxy class]]) { [(TiWindowProxy *)contentViewProxy setIsManaged:YES]; viewController = [[(TiWindowProxy *)contentViewProxy hostingController] retain]; - //[viewController.view addObserver:self forKeyPath:@"safeAreaInsets" options:NSKeyValueObservingOptionNew | NSKeyValueObservingOptionOld context:nil]; + [viewController.view addObserver:self forKeyPath:@"safeAreaInsets" options:NSKeyValueObservingOptionNew | NSKeyValueObservingOptionOld context:nil]; } else { - // - viewController = [[TiViewController alloc] initWithViewProxy:contentViewProxy]; - // [viewController.view addObserver:self forKeyPath:@"safeAreaInsets" options:NSKeyValueObservingOptionNew | NSKeyValueObservingOptionOld context:nil]; + [viewController.view addObserver:self forKeyPath:@"safeAreaInsets" options:NSKeyValueObservingOptionNew | NSKeyValueObservingOptionOld context:nil]; } } viewController.view.clipsToBounds = NO; @@ -487,20 +433,10 @@ - (UIViewController *)viewController - (void)cleanup { currentTiBottomSheet = nil; - // NSLog(@"cleanup 1 "); - - // NSLog(@"cleanup 2 "); - - [contentViewProxy setProxyObserver:nil]; [contentViewProxy windowWillClose]; - - popoverInitialized = NO; - // [self fireEvent:@"hide" withObject:nil]; //Checking for listeners are done by fireEvent anyways. -// [[NSNotificationCenter defaultCenter] removeObserver:self name:UIApplicationWillChangeStatusBarOrientationNotification object:nil]; + bottomSheetInitialized = NO; [contentViewProxy windowDidClose]; - // NSLog(@"cleanup 3 "); - if ([contentViewProxy isKindOfClass:[TiWindowProxy class]]) { UIView *topWindowView = [[[TiApp app] controller] topWindowProxyView]; if ([topWindowView isKindOfClass:[TiUIView class]]) { @@ -510,40 +446,37 @@ - (void)cleanup } } } - // NSLog(@"cleanup 4 "); - [self forgetSelf]; [viewController.view removeObserver:self forKeyPath:@"safeAreaInsets"]; RELEASE_TO_NIL(viewController); - // NSLog(@"cleanup 5 "); - [self performSelector:@selector(release) withObject:nil afterDelay:0.5]; [bottomSheetclosingCondition lock]; isDismissing = NO; + nonSystemSheetAutomaticStartPositionFromContentViewHeight = NO; [bottomSheetclosingCondition signal]; [bottomSheetclosingCondition unlock]; - - // NSLog(@"cleanup 6 "); - - popoverInitialized = NO; - currentTiBottomSheet = nil; - // NSLog(@"cleanup 7 "); - - RELEASE_TO_NIL(bottomSheetclosingCondition); - RELEASE_TO_NIL(contentViewProxy); - // bottomSheet.delegate = nil; - //RELEASE_TO_NIL(bottomSheet); - // NSLog(@"cleanup 8 "); - + bottomSheetInitialized = NO; + currentTiBottomSheet = nil; + RELEASE_TO_NIL(currentTiBottomSheet); + RELEASE_TO_NIL(bottomSheetclosingCondition); + RELEASE_TO_NIL(contentViewProxy); + RELEASE_TO_NIL(centerProxy); } - (void)initAndShowSheetController { - // NSLog(@"initAndShowSheetController "); + self.fixedHeight = NO; + self.insetsDone = NO; + if (nonSystemSheetAutomaticStartPositionFromContentViewHeight == YES){ + nonSystemSheetShouldScroll = NO; + self.fixedHeight = YES; + } deviceRotated = NO; currentTiBottomSheet = self; [contentViewProxy setProxyObserver:self]; + scrollableContentHeight = 0; + if ([contentViewProxy isKindOfClass:[TiWindowProxy class]]) { useNavController = YES; @@ -554,72 +487,226 @@ - (void)initAndShowSheetController [(id)theProxy resignFocus]; } } - [(TiWindowProxy *)contentViewProxy setIsManaged:YES]; - [(TiWindowProxy *)contentViewProxy open:nil]; - [(TiWindowProxy *)contentViewProxy gainFocus]; - - if (closeButtonProxy){ - [closeButtonProxy windowWillOpen]; - [closeButtonProxy reposition]; - [closeButtonProxy layoutChildrenIfNeeded]; - - CGFloat width = [closeButtonProxy autoWidthForSize:CGSizeMake(1000, 1000)]; - CGFloat height = [closeButtonProxy autoHeightForSize:CGSizeMake(width, 0)]; - CGRect closeButtonViewFrame = CGRectMake( 0 , 0, width, height); - closeButtonView = [[UIView alloc] initWithFrame:closeButtonViewFrame]; - // NSLog(@"closeButton %f x %f",width,height); - } + + [(TiWindowProxy *)contentViewProxy setIsManaged:YES]; + [(TiWindowProxy *)contentViewProxy open:nil]; + [(TiWindowProxy *)contentViewProxy gainFocus]; + [(TiWindowProxy *)contentViewProxy reposition]; + [(TiWindowProxy *)contentViewProxy layoutChildrenIfNeeded]; + if (closeButtonProxy){ + [closeButtonProxy windowWillOpen]; + [closeButtonProxy reposition]; + [closeButtonProxy layoutChildrenIfNeeded]; + + CGFloat width = [closeButtonProxy autoWidthForSize:CGSizeMake(1000, 1000)]; + CGFloat height = [closeButtonProxy autoHeightForSize:CGSizeMake(width, 0)]; + CGRect closeButtonViewFrame = CGRectMake( 0 , 0, width, height); + closeButtonView = [[UIView alloc] initWithFrame:closeButtonViewFrame]; + } dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{ + if ([[[contentViewProxy class] description] isEqualToString:@"TiUINavigationWindowProxy"]) { + TiWindowProxy *childWindowProxy = [contentViewProxy valueForKey:@"window"]; + + id childWindowProxyHeight = [childWindowProxy valueForUndefinedKey:@"height"]; + if (childWindowProxyHeight && (![childWindowProxyHeight isEqual:@"SIZE"] && ![childWindowProxyHeight isEqual:@"FILL"])) { + self.fixedHeight = YES; + } + + realContentHeight = [(TiWindowProxy *)childWindowProxy view].frame.size.height; + if (realContentHeight >= [UIScreen mainScreen].bounds.size.height){ + realContentHeight = realContentHeight - 200; + } + } + else { + id contentViewProxyHeight = [contentViewProxy valueForUndefinedKey:@"height"]; + if (contentViewProxyHeight && (![contentViewProxyHeight isEqual:@"SIZE"] && ![contentViewProxyHeight isEqual:@"FILL"])) { + self.fixedHeight = YES; + } + + realContentHeight = [(TiWindowProxy *)contentViewProxy view].frame.size.height; + if (realContentHeight >= [UIScreen mainScreen].bounds.size.height){ + realContentHeight = realContentHeight - 200; + } + } + [self updatePopoverNow]; [contentViewProxy windowDidOpen]; }); } else { - [contentViewProxy windowWillOpen]; - [contentViewProxy reposition]; - // NSLog(@"closeButtonProxy %@",closeButtonProxy); - - if (closeButtonProxy){ - [closeButtonProxy windowWillOpen]; - [closeButtonProxy reposition]; - [closeButtonProxy layoutChildrenIfNeeded]; - CGFloat width = [closeButtonProxy autoWidthForSize:CGSizeMake(1000, 1000)]; - CGFloat height = [closeButtonProxy autoHeightForSize:CGSizeMake(width, 0)]; - CGRect closeButtonViewFrame = CGRectMake( 0 , 0, width, height); - closeButtonView = [[UIView alloc] initWithFrame:closeButtonViewFrame]; - // NSLog(@"closeButton %f x %f",width,height); + CGSize reCalculatedSize; + reCalculatedSize.height = 0; + [contentViewProxy windowWillOpen]; + [contentViewProxy reposition]; + + id contentViewProxyHeight = [contentViewProxy valueForUndefinedKey:@"height"]; + if (contentViewProxyHeight && (![contentViewProxyHeight isEqual:@"SIZE"] && ![contentViewProxyHeight isEqual:@"FILL"])) { + self.fixedHeight = YES; } - [self updateContentSize]; - // NSLog(@"before updatePopoverNow "); + + if (nonSystemSheetShouldScroll == YES && defaultsToNonSystemSheet == YES){ + if ([contentViewProxy.view isKindOfClass:[TiUIListView class]] || [contentViewProxy.view isKindOfClass:[TiUITableView class]] || [contentViewProxy.view isKindOfClass:[TiUIScrollViewImpl class]] || [NSStringFromClass([contentViewProxy.view class]) isEqual: @"TiCollectionviewCollectionView"]) { - dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{ - [self updatePopoverNow]; - [contentViewProxy windowDidOpen]; - }); + + UITableView *sv = nil; + + + if ([contentViewProxy.view isKindOfClass:[TiUITableView class]]){ + + object_setClass(sv, [UITableView class]); + sv = (UITableView *)[(TiUITableView*)contentViewProxy.view tableView]; + if ([sv isScrollEnabled] == NO){ + reCalculatedSize = sv.contentSize; + CGRect newFrame = contentViewProxy.view.frame; + newFrame.size.height = reCalculatedSize.height; + contentViewProxy.view.frame = newFrame; + [contentViewProxy replaceValue:@"Ti.UI.SIZE" forKey:@"height" notification:YES]; + } + else { + nonSystemSheetShouldScroll = NO; + } + } + else if ([contentViewProxy.view isKindOfClass:[TiUIListView class]]){ + object_setClass(sv, [UITableView class]); + sv = [(TiUIListView*)contentViewProxy.view tableView]; + if ([sv isScrollEnabled] == NO){ + reCalculatedSize = sv.contentSize; + + [contentViewProxy replaceValue:@"false" forKey:@"canScroll" notification:YES]; + [contentViewProxy replaceValue:@"Ti.UI.SIZE" forKey:@"height" notification:YES]; } + else { + nonSystemSheetShouldScroll = NO; + } + } + else if ([NSStringFromClass([contentViewProxy.view class]) isEqual: @"TiCollectionviewCollectionView"]){ + reCalculatedSize = [self contentSize:contentViewProxy]; + + } + else { + object_setClass(sv, [TiUIScrollViewImpl class]); + sv = [(TiUIScrollView*)contentViewProxy.view scrollView]; + if ([sv isScrollEnabled] == NO){ + reCalculatedSize = sv.contentSize; + [contentViewProxy replaceValue:@"Ti.UI.SIZE" forKey:@"height" notification:YES]; + [contentViewProxy replaceValue:@"false" forKey:@"scrollingEnabled" notification:YES]; + } + else { + nonSystemSheetShouldScroll = NO; + } + } + + } + else { + + for (TiViewProxy * proxy in [contentViewProxy children]) { + + UITableView *sv = nil; + + [proxy windowWillOpen]; + [proxy reposition]; + + if ([proxy.view isKindOfClass:[TiUIListView class]] || [proxy.view isKindOfClass:[TiUITableView class]] || [proxy.view isKindOfClass:[TiUIScrollViewImpl class]] || [NSStringFromClass([proxy.view class]) isEqual: @"TiCollectionviewCollectionView"]) { + + if ([proxy.view isKindOfClass:[TiUITableView class]]){ + + object_setClass(sv, [UITableView class]); + sv = (UITableView *)[(TiUITableView*)proxy.view tableView]; + + [proxy replaceValue:@"false" forKey:@"scrollable" notification:YES]; + reCalculatedSize = sv.contentSize; + CGRect newFrame = proxy.view.frame; + newFrame.size.height = reCalculatedSize.height; + proxy.view.frame = newFrame; + [proxy replaceValue:[NSNumber numberWithInt:reCalculatedSize.height] forKey:@"height" notification:YES]; + } + else if ([proxy.view isKindOfClass:[TiUIListView class]]){ + object_setClass(sv, [UITableView class]); + sv = [(TiUIListView*)proxy.view tableView]; + reCalculatedSize = sv.contentSize; + [proxy replaceValue:@"false" forKey:@"canScroll" notification:YES]; + CGRect newFrame = proxy.view.frame; + newFrame.size.height = reCalculatedSize.height; + proxy.view.frame = newFrame; + [proxy replaceValue:[NSNumber numberWithInt:reCalculatedSize.height] forKey:@"height" notification:YES]; + + } + else if ([NSStringFromClass([proxy.view class]) isEqual: @"TiCollectionviewCollectionView"]){ + object_setClass(sv, [UICollectionView class]); + + sv = [proxy.view performSelector:@selector(collectionView)]; + reCalculatedSize = [self contentSize:proxy]; + CGRect newFrame = proxy.view.frame; + newFrame.size.height = reCalculatedSize.height; + proxy.view.frame = newFrame; + [proxy replaceValue:[NSNumber numberWithInt:reCalculatedSize.height] forKey:@"height" notification:YES]; + + } + else { + object_setClass(sv, [TiUIScrollViewImpl class]); + sv = [(TiUIScrollView*)proxy.view scrollView]; + reCalculatedSize = sv.contentSize; + [proxy replaceValue:@"false" forKey:@"scrollingEnabled" notification:YES]; + CGRect newFrame = proxy.view.frame; + newFrame.size.height = reCalculatedSize.height; + proxy.view.frame = newFrame; + [proxy replaceValue:[NSNumber numberWithInt:reCalculatedSize.height] forKey:@"height" notification:YES]; + } + } + } + } + scrollableContentHeight = reCalculatedSize.height; + } + else { + scrollableContentHeight = 0; + } + + if (closeButtonProxy){ + [closeButtonProxy windowWillOpen]; + [closeButtonProxy reposition]; + [closeButtonProxy layoutChildrenIfNeeded]; + CGFloat width = [closeButtonProxy autoWidthForSize:CGSizeMake(1000, 1000)]; + CGFloat height = [closeButtonProxy autoHeightForSize:CGSizeMake(width, 0)]; + CGRect closeButtonViewFrame = CGRectMake( 0 , 0, width, height); + closeButtonView = [[UIView alloc] initWithFrame:closeButtonViewFrame]; + } + + realContentHeight = [self updateContentSizeWithReturn].height; + + dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{ + if (realContentHeight >= [UIScreen mainScreen].bounds.size.height){ + realContentHeight = realContentHeight - 200; + } + + if (scrollableContentHeight == 0){ + scrollableContentHeight = realContentHeight; + } + [self updatePopoverNow]; + [contentViewProxy windowDidOpen]; + }); } } -- (CGSize)contentSize +- (CGSize)contentSize:(TiViewProxy *)thisProxy { #ifndef TI_USE_AUTOLAYOUT CGSize screenSize = [[UIScreen mainScreen] bounds].size; if (poWidth.type != TiDimensionTypeUndefined) { - [contentViewProxy layoutProperties]->width.type = poWidth.type; - [contentViewProxy layoutProperties]->width.value = poWidth.value; + [thisProxy layoutProperties]->width.type = poWidth.type; + [thisProxy layoutProperties]->width.value = poWidth.value; poWidth = TiDimensionUndefined; } if (poHeight.type != TiDimensionTypeUndefined) { - [contentViewProxy layoutProperties]->height.type = poHeight.type; - [contentViewProxy layoutProperties]->height.value = poHeight.value; + [thisProxy layoutProperties]->height.type = poHeight.type; + [thisProxy layoutProperties]->height.value = poHeight.value; poHeight = TiDimensionUndefined; } - TiBottomSheetContentSize = SizeConstraintViewWithSizeAddingResizing([contentViewProxy layoutProperties], contentViewProxy, screenSize, NULL); + TiBottomSheetContentSize = SizeConstraintViewWithSizeAddingResizing([thisProxy layoutProperties], thisProxy, screenSize, NULL); return TiBottomSheetContentSize; #else @@ -629,30 +716,41 @@ - (CGSize)contentSize - (void)updateContentSize { -// NSLog(@"updateContentSize "); - CGSize newSize = [self contentSize]; + TiThreadPerformOnMainThread( + ^{ + CGSize newSize = [self contentSize:contentViewProxy]; + + if (defaultsToNonSystemSheet == NO){ + [[self viewController] setPreferredContentSize:newSize]; + } + [contentViewProxy reposition]; + }, + NO); +} + + + +- (CGSize)updateContentSizeWithReturn +{ + CGSize newSize = [self contentSize:contentViewProxy]; if (defaultsToNonSystemSheet == NO){ - [[self viewController] setPreferredContentSize:newSize]; + [[self viewController] setPreferredContentSize:newSize]; } [contentViewProxy reposition]; - + return newSize; } - (void)updatePopoverNow { - // NSLog(@"updatePopoverNow "); if (![self valueForKey:@"backgroundColor"] || [[self valueForKey:@"backgroundColor"] isEqual:@"transparent"]){ [self replaceValue:[TiUtils hexColorValue:[UIColor lightGrayColor]] forKey:@"backgroundColor" notification:YES]; } - if (defaultsToNonSystemSheet == NO){ UIViewController *theController = [self viewController]; - bottomSheet = [theController sheetPresentationController]; - bottomSheet.delegate = self; if ([self valueForKey:@"largestUndimmedDetentIdentifier"]){ @@ -673,21 +771,14 @@ - (void)updatePopoverNow if ([self valueForKey:@"preferredCornerRadius"]){ bottomSheet.preferredCornerRadius = [TiUtils floatValue:[self valueForKey:@"preferredCornerRadius"]]; } - - - - - bottomSheet.prefersScrollingExpandsWhenScrolledToEdge = [TiUtils boolValue:[self valueForKey:@"prefersScrollingExpandsWhenScrolledToEdge"] def:YES]; + bottomSheet.prefersScrollingExpandsWhenScrolledToEdge = [TiUtils boolValue:[self valueForKey:@"prefersScrollingExpandsWhenScrolledToEdge"] def:NO]; - bottomSheet.prefersEdgeAttachedInCompactHeight = [TiUtils boolValue:[self valueForKey:@"prefersEdgeAttachedInCompactHeight"] def:YES]; + bottomSheet.prefersEdgeAttachedInCompactHeight = [TiUtils boolValue:[self valueForKey:@"prefersEdgeAttachedInCompactHeight"] def:NO]; - bottomSheet.widthFollowsPreferredContentSizeWhenEdgeAttached = [TiUtils boolValue:[self valueForKey:@"widthFollowsPreferredContentSizeWhenEdgeAttached"] def:YES]; + bottomSheet.widthFollowsPreferredContentSizeWhenEdgeAttached = [TiUtils boolValue:[self valueForKey:@"widthFollowsPreferredContentSizeWhenEdgeAttached"] def:NO]; - - - if ([self valueForKey:@"detents"]){ userDetents = [self valueForKey:@"detents"]; @@ -729,20 +820,15 @@ - (void)updatePopoverNow } - bottomSheet.prefersGrabberVisible = [TiUtils boolValue:[self valueForKey:@"prefersGrabberVisible"] def:YES]; + bottomSheet.prefersGrabberVisible = [TiUtils boolValue:[self valueForKey:@"prefersGrabberVisible"] def:YES]; + CGRect handleViewContainerFrame = CGRectMake( 0, 0, contentViewProxy.view.frame.size.width , 20); + UIView *handleContainer = [[UIView alloc] initWithFrame:handleViewContainerFrame]; + [contentViewProxy.view addSubview:handleContainer]; + [handleContainer release]; - - if ([self valueForKey:@"backgroundColor"]){ - - // [theController.view setBackgroundColor:[[TiUtils colorValue:[self valueForKey:@"backgroundColor"]] _color]]; - -// [theController.view setBackgroundColor:[[TiUtils colorValue:[self valueForKey:@"backgroundColor"]] _color]]; - } [theController.view setBackgroundColor:[[TiUtils colorValue:[self valueForKey:@"backgroundColor"]] _color]]; - // [theController.view setBackgroundColor:[UIColor redColor]]; - if ([self valueForKey:@"modalPresentation"]){ if ([[TiUtils stringValue:[self valueForKey:@"modalPresentation"]] isEqual: @"fullScreen"]){ [theController setModalPresentationStyle:UIModalPresentationFullScreen]; @@ -765,8 +851,6 @@ - (void)updatePopoverNow } - // NSLog(@"before closeButtonView "); - if (closeButtonView != nil){ closeButtonProxy.view.frame = closeButtonView.bounds; [closeButtonView addSubview:closeButtonProxy.view]; @@ -777,24 +861,18 @@ - (void)updatePopoverNow [theController.view addSubview:closeButtonView]; [theController.view bringSubviewToFront:closeButtonView]; - - // NSLog(@"added closeButtonView "); - // NSLog(@"closeButtonView %@",closeButtonView); } - [[[[TiApp app] controller] topPresentedController] presentViewController:theController animated:animated completion:^{ - [self fireEvent:@"opened" withObject:nil]; - - }]; - - + + [[[[TiApp app] controller] topPresentedController] presentViewController:theController animated:animated completion:^{ + [self fireEvent:@"opened" withObject:nil]; + }]; } else { customBottomSheet = [BottomSheetViewController new]; [customBottomSheet setProxyOfBottomSheetController:self]; - - + const CGFloat y = [[[TiApp app] controller] topPresentedController].view.frame.origin.y; const CGFloat height = [[[TiApp app] controller] topPresentedController].view.frame.size.height; const CGFloat width = [[[TiApp app] controller] topPresentedController].view.frame.size.width; @@ -811,97 +889,107 @@ - (void)updatePopoverNow customBottomSheet.view.frame = CGRectMake( 0, y + height, width, height); containerView = [[UIView alloc] init]; - + if ([TiUtils boolValue:[self valueForUndefinedKey:@"nonSystemSheetTopShadow"] def:NO]){ customBottomSheet.view.layer.shadowOffset = CGSizeMake(0,-2); customBottomSheet.view.layer.shadowRadius = 6; customBottomSheet.view.layer.shadowOpacity = .6f; customBottomSheet.view.layer.shadowColor = [UIColor blackColor].CGColor; - //customBottomSheet.view.layer.masksToBounds = NO; } containerView.clipsToBounds = YES; - - - [customBottomSheet.view addSubview:containerView]; - const CGFloat heightOfContainer = customBottomSheet.view.frame.size.height - 100; - const CGFloat widthOfContainer = customBottomSheet.view.frame.size.width; - containerView.frame = CGRectMake( 0, 0, widthOfContainer, heightOfContainer); - - - useNavController = NO; if ([[[contentViewProxy class] description] isEqualToString:@"TiUINavigationWindowProxy"]) { useNavController = YES; } - - UIView *controllerView_; if (useNavController) { - //[(TiWindowProxy *)contentViewProxy setIsManaged:YES]; centerProxy = [self valueForUndefinedKey:@"contentView"]; - controllerView_ = [[centerProxy controller] view]; - [controllerView_ setFrame:[containerView bounds]]; + contentViewOfSheet = [[centerProxy controller] view]; } else { - controllerView_ = [contentViewProxy view]; - [controllerView_ setFrame:[containerView bounds]]; + contentViewOfSheet = [contentViewProxy view]; } - + CGFloat heightOfContainer; + CGFloat widthOfContainer = customBottomSheet.view.frame.size.width; + if (nonSystemSheetAutomaticStartPositionFromContentViewHeight == YES){ + nonSystemSheetShouldScroll = NO; + heightOfContainer = realContentHeight + bottomSheetSafeAreaInset.bottom; + } + else { + heightOfContainer = customBottomSheet.view.frame.size.height; + } + containerView.frame = CGRectMake( 0, 0, widthOfContainer, heightOfContainer); + CGRect controllerViewFrame = CGRectMake( 0, 0, widthOfContainer, heightOfContainer); if (nonSystemSheetShouldScroll == YES){ - - // NSLog(@"nonSystemSheetShouldScroll == YES "); - UIEdgeInsets safeAreaInset = UIEdgeInsetsZero; - UIViewController *topContainerController = [[[TiApp app] controller] topContainerController]; - - safeAreaInset = [[topContainerController hostingView] safeAreaInsets]; - - const CGFloat heightOfScrollContainer = containerView.frame.size.height; - const CGFloat widthOfScrollContainer = containerView.frame.size.width; + if (useNavController == YES){ + scrollableContentHeight = realContentHeight; + // controllerViewFrame.size.height = scrollableContentHeight; + + if (self.fixedHeight == YES){ + controllerViewFrame.size.height = realContentHeight; + } + + } + else { + if (scrollableContentHeight > 0){ + controllerViewFrame.size.height = scrollableContentHeight; + } + else { + scrollableContentHeight = realContentHeight; + } + } + [contentViewOfSheet setFrame:controllerViewFrame]; + + const CGFloat heightOfScrollContainer = containerView.frame.size.height; + const CGFloat widthOfScrollContainer = containerView.frame.size.width; scrollView = [[ContentScrollView alloc] initWithFrame:CGRectMake( 0, 0, widthOfScrollContainer, heightOfScrollContainer)]; + [customBottomSheet scrollView:scrollView]; + scrollView.dismissing = NO; scrollView.delegate = self; -// UITapGestureRecognizer *panScrollView = -// [[UITapGestureRecognizer alloc] initWithTarget:self -// action:@selector(handleGesture:)]; -// [scrollView addGestureRecognizer:panScrollView]; scrollView.delaysContentTouches = NO; - scrollView.scrollEnabled = YES; - // scrollView.pagingEnabled = YES; - scrollView.showsVerticalScrollIndicator = YES; - scrollView.showsHorizontalScrollIndicator = NO; + scrollView.scrollEnabled = YES; + // scrollView.pagingEnabled = YES; + scrollView.alwaysBounceVertical = NO; + scrollView.showsVerticalScrollIndicator = YES; + scrollView.showsHorizontalScrollIndicator = NO; scrollView.canCancelContentTouches = YES; - scrollView.contentSize = CGSizeMake(controllerView_.frame.size.width, controllerView_.frame.size.height); - // NSLog(@"contentSize height %f ",[contentViewProxy view].frame.size.height); - scrollView.insetsLayoutMarginsFromSafeArea = YES; + scrollView.contentInset = UIEdgeInsetsMake(0, 0, bottomSheetSafeAreaInset.bottom, 0); + [scrollView setScrollIndicatorInsets:UIEdgeInsetsMake(20, 0, bottomSheetSafeAreaInset.bottom, 0)]; + //scrollView.insetsLayoutMarginsFromSafeArea = YES; [containerView addSubview:scrollView]; - [scrollView addSubview:controllerView_]; + [scrollView addSubview:contentViewOfSheet]; + scrollView.contentSize = CGSizeMake(contentViewOfSheet.frame.size.width, scrollableContentHeight); CGPoint contentOffet = scrollView.contentOffset; contentOffet.y = 0; scrollView.contentOffset = contentOffet; - //[customBottomSheet panRecognizerEnabled:NO]; [customBottomSheet panRecognizerEnabled:YES]; - [customBottomSheet scrollView:scrollView]; - [customBottomSheet lastContentOffsetY:0]; - - - [self disableScrolling:controllerView_]; - } else { - // NSLog(@"nonSystemSheetShouldScroll == NO "); - - [containerView addSubview:controllerView_]; + if (self.fixedHeight == NO){ + controllerViewFrame.size.height = controllerViewFrame.size.height - bottomSheetSafeAreaInset.bottom; + } + else { + if (nonSystemSheetAutomaticStartPositionFromContentViewHeight == YES){ + controllerViewFrame.size.height = realContentHeight + bottomSheetSafeAreaInset.bottom; + } + else { + controllerViewFrame.size.height = realContentHeight; + } + } + + [contentViewOfSheet setFrame:controllerViewFrame]; + [containerView addSubview:contentViewOfSheet]; + [self scrollingInsets:contentViewOfSheet]; } - - if ([self valueForKey:@"preferredCornerRadius"]){ containerView.layer.cornerRadius = [TiUtils floatValue:[self valueForKey:@"preferredCornerRadius"]]; } @@ -910,63 +998,38 @@ - (void)updatePopoverNow } containerView.backgroundColor = [[TiUtils colorValue:[self valueForKey:@"backgroundColor"]] _color]; - + + CGRect handleViewContainerFrame = CGRectMake( 0, 0, containerView.frame.size.width , 20); + UIView *handleContainer = [[UIView alloc] initWithFrame:handleViewContainerFrame]; + if (nonSystemSheetShouldScroll == YES){ + [containerView insertSubview:handleContainer aboveSubview:scrollView]; + } + else { + [containerView insertSubview:handleContainer aboveSubview:contentViewOfSheet]; + } + [handleContainer release]; + if ([TiUtils boolValue:[self valueForKey:@"prefersGrabberVisible"] def:YES]){ CGRect handleViewFrame = CGRectMake( 0, 0, 36, 5); UIView *handle = [[UIView alloc] initWithFrame:handleViewFrame]; handle.backgroundColor = [self adaptiveGrabberColor]; handle.layer.cornerRadius = 4; - CGSize size = containerView.frame.size; - [handle setCenter:CGPointMake(size.width/2, 10)]; - - if (nonSystemSheetShouldScroll == YES){ - [containerView insertSubview:handle aboveSubview:scrollView]; - } - else { - [containerView insertSubview:handle aboveSubview:controllerView_]; - } - + [handle setCenter:CGPointMake(containerView.frame.size.width/2, 10)]; + [handleContainer addSubview:handle]; [handle release]; } if (closeButtonView != nil){ - closeButtonProxy.view.frame = closeButtonView.bounds; [closeButtonView addSubview:closeButtonProxy.view]; [closeButtonProxy reposition]; - - - CGSize size = containerView.frame.size; - - [closeButtonView setCenter:CGPointMake((size.width - (closeButtonView.bounds.size.width/2)), 24)]; - - if (nonSystemSheetShouldScroll == YES){ - [containerView insertSubview:closeButtonView aboveSubview:scrollView]; - } - else { - [containerView insertSubview:closeButtonView aboveSubview:controllerView_]; - } + [closeButtonView setCenter:CGPointMake((containerView.frame.size.width - (closeButtonView.bounds.size.width/2)), 24)]; + [containerView insertSubview:closeButtonView aboveSubview:handleContainer]; } - - - // [[[[TiApp app] controller] topPresentedController] presentViewController:theController animated:animated completion:^{ -// }]; - - - [[[[TiApp app] controller] topPresentedController].view addSubview:backgroundView]; - [[[[TiApp app] controller] topPresentedController].view insertSubview:customBottomSheet.view aboveSubview:backgroundView]; - - - - // [[[[TiApp app] controller] topPresentedController].view addSubview:theController.view]; - // [[TiApp app] showModalController:theController animated:animated]; - - [self fireEvent:@"opened" withObject:nil]; - } } @@ -982,51 +1045,50 @@ - (UIColor *)adaptiveGrabberColor return [UIColor colorWithRed:0.77 green:0.77 blue:0.78 alpha:1.0]; } -- (void)disableScrolling:(UIView *)view +- (void)scrollingInsets:(UIView *)view { - - if ([view respondsToSelector:@selector(setScrollEnabled:)]){ - // NSLog(@"UIView %@ ",view); + if ([view respondsToSelector:@selector(setScrollEnabled:)] && self.insetsDone == NO){ - if ([view performSelector: @selector (isScrollEnabled)]){ + CGFloat bottomInset = 0; + if (self.fixedHeight == NO){ + bottomInset = bottomSheetSafeAreaInset.bottom; + } if ([view isKindOfClass:[UITableView class]]){ - [(UITableView *)view setScrollEnabled:NO]; - // NSLog(@"TableView %@ ",view); + + if (nonSystemSheetAutomaticStartPositionFromContentViewHeight == YES){ + bottomInset = bottomSheetSafeAreaInset.bottom; + // CGRect newFrame = [(UITableView *)view frame]; + // newFrame.size.height = newFrame.size.height + bottomSheetSafeAreaInset.bottom; + // [(UITableView *)view setFrame:newFrame]; + } + + [(UITableView *)view setScrollIndicatorInsets:UIEdgeInsetsMake(20, 0, bottomInset, 0)]; + [(UITableView *)view setContentInset:UIEdgeInsetsMake(0, 0, bottomInset, 0)]; + self.insetsDone = YES; } else if ([view isKindOfClass:[UIScrollView class]]){ - [(UIScrollView *)view setScrollEnabled:NO]; - // NSLog(@"ScrollView %@ ",view); + if (nonSystemSheetAutomaticStartPositionFromContentViewHeight == YES){ + bottomInset = bottomSheetSafeAreaInset.bottom; + + // CGRect newFrame = [(UIScrollView *)view frame]; + // newFrame.size.height = newFrame.size.height + bottomSheetSafeAreaInset.bottom; + // [(UIScrollView *)view setFrame:newFrame]; + } + + [(UIScrollView *)view setScrollIndicatorInsets:UIEdgeInsetsMake(20, 0, bottomInset, 0)]; + [(UIScrollView *)view setContentInset:UIEdgeInsetsMake(0, 0, bottomInset, 0)]; + self.insetsDone = YES; } else { // NSLog(@"UIView isScrollEnabled %d ",[view performSelector: @selector (isScrollEnabled)]); } - } } - - for (UIView *eachView in view.subviews) { - - if ([eachView respondsToSelector:@selector(setScrollEnabled:)]){ - // NSLog(@"UIView %@ ",eachView); - - if ([eachView performSelector: @selector (isScrollEnabled)]){ - - if ([eachView isKindOfClass:[UITableView class]]){ - [(UITableView *)eachView setScrollEnabled:NO]; - //NSLog(@"TableView %@ ",eachView); - - } - else if ([eachView isKindOfClass:[UIScrollView class]]){ - [(UIScrollView *)eachView setScrollEnabled:NO]; - //NSLog(@"ScrollView %@ ",eachView); - } - else { - // NSLog(@"UIView isScrollEnabled %d ",[eachView performSelector: @selector (isScrollEnabled)]); - } + else { + for (UIView *eachView in view.subviews) { + [self scrollingInsets:eachView]; } - } - [self disableScrolling:eachView]; } } @@ -1039,13 +1101,11 @@ - (void)handleSingleTap:(UITapGestureRecognizer *)recognizer isDismissing = YES; [self hide:nil]; } - //Do stuff here... } - (void)handleGesture:(UITapGestureRecognizer *)recognizer { if (scrollView.dismissing == NO){ - // NSLog(@"*************** handleGesture"); [customBottomSheet panFromScrollView:YES]; } } @@ -1055,30 +1115,18 @@ - (void)updateContentViewWithSafeAreaInsets:(NSValue *)insetsValue { TiThreadPerformOnMainThread( ^{ - UIViewController *viewController = [self viewController]; - -// CGRect newControllerFrame = viewController.view.frame; -// -// newControllerFrame.size.height = viewController.view.frame.size.height + 24; -// viewController.view.frame = newControllerFrame; - - self->contentViewProxy.view.frame = viewController.view.frame; - -// CGRect controllerFrame = viewController.view.frame; -// controllerFrame.origin.y = 24; -// // controllerFrame.size.height = controllerFrame.size.height - 24; -// self->contentViewProxy.view.frame = controllerFrame; - -// - UIEdgeInsets edgeInsets = [insetsValue UIEdgeInsetsValue]; -// - viewController.view.frame = CGRectMake(viewController.view.frame.origin.x + edgeInsets.left, viewController.view.frame.origin.y + (edgeInsets.top), viewController.view.frame.size.width - edgeInsets.left - edgeInsets.right, viewController.view.frame.size.height - (edgeInsets.top) - edgeInsets.bottom); - + UIEdgeInsets edgeInsets = [insetsValue UIEdgeInsetsValue]; -// -// -// self->contentViewProxy.view.frame = CGRectMake(self->contentViewProxy.view.frame.origin.x + edgeInsets.left, self->contentViewProxy.view.frame.origin.y + (edgeInsets.top), self->contentViewProxy.view.frame.size.width - edgeInsets.left - edgeInsets.right, self->contentViewProxy.view.frame.size.height - (edgeInsets.top) - edgeInsets.bottom); - + if (defaultsToNonSystemSheet == YES){ + if (useNavController == YES && nonSystemSheetShouldScroll == NO){ + [[self->contentViewProxy controller] view].frame = CGRectMake([[self->contentViewProxy controller] view].frame.origin.x + edgeInsets.left, [[self->contentViewProxy controller] view].frame.origin.y + (edgeInsets.top), [[self->contentViewProxy controller] view].frame.size.width - edgeInsets.left - edgeInsets.right, [[self->contentViewProxy controller] view].frame.size.height - (edgeInsets.top) - edgeInsets.bottom); + } + else { + if (nonSystemSheetShouldScroll == NO) { + self->contentViewProxy.view.frame = CGRectMake(self->contentViewProxy.view.frame.origin.x + edgeInsets.left, self->contentViewProxy.view.frame.origin.y + (edgeInsets.top), self->contentViewProxy.view.frame.size.width - edgeInsets.left - edgeInsets.right, self->contentViewProxy.view.frame.size.height - (edgeInsets.top) - edgeInsets.bottom); + } + } + } }, NO); } @@ -1087,93 +1135,59 @@ - (void)updateContentViewWithSafeAreaInsets:(NSValue *)insetsValue -(void)scrollViewDidScroll:(ContentScrollView *)scrollView{ - - // NSLog(@"++++++++++ scrollViewDidScroll "); - - [customBottomSheet lastContentOffsetY:scrollView.contentOffset.y]; - + if (scrollView.contentOffset.y <= 0) { //scrollView.contentOffset = CGPointZero; - if (scrollView.dismissing == NO){ scrollView.dismissing = YES; - [customBottomSheet panRecognizerInit:YES]; - [customBottomSheet panRecognizerEnabled:YES]; - // scrollView.panGestureRecognizer.enabled = NO; - // scrollView.panGestureRecognizer.enabled = NO; - // NSLog(@"++++++++++ scrollViewDidScroll disable ScrollView "); - } } else { scrollView.dismissing = NO; - [customBottomSheet panRecognizerEnabled:NO]; - // scrollView.panGestureRecognizer.enabled = YES; - // NSLog(@"++++++++++ scrollViewDidScroll enable ScrollView "); - // [customBottomSheet panFromScrollView:NO]; - -// if (scrollView.panGestureRecognizer.enabled == NO){ -// scrollView.panGestureRecognizer.enabled = YES; -// } } - } // - (void)scrollViewDidEndDecelerating:(ContentScrollView *)scrollView_ // scrolling has ended { - [customBottomSheet panRecognizerEnabled:YES]; - // NSLog(@"scrollViewDidEndDecelerating "); - // scrollView.panGestureRecognizer.enabled = YES; scrollView.dismissing = NO; - [customBottomSheet panFromScrollView:NO]; -// scrollView.panGestureRecognizer.enabled = YES; - // [customBottomSheet panRecognizerEnabled:YES]; - } // - (void)scrollViewDidEndDragging:(ContentScrollView *)scrollView willDecelerate:(BOOL)decelerate { - // NSLog(@"scrollViewDidEndDragging "); scrollView.dismissing = NO; - // scrollView.panGestureRecognizer.enabled = YES; - [customBottomSheet panRecognizerEnabled:YES]; - [customBottomSheet panFromScrollView:NO]; - - // [customBottomSheet panFromScrollView:NO]; - } -// + //-(void)scrollViewWillBeginDragging:(ContentScrollView *)scrollView{ // // [customBottomSheet panRecognizerEnabled:NO]; // NSLog(@"scrollViewWillBeginDragging "); // if ([customBottomSheet panRecognizerState] == YES) { // NSLog(@"scrollViewWillBeginDragging pan disabled"); -// [customBottomSheet panRecognizerEnabled:NO]; +// [customBottomSheet :NO]; // } //} - - (void)proxyDidRelayout:(id)sender { - if (sender == contentViewProxy) { - if (viewController != nil) { - CGSize newSize = [self contentSize]; - if (TiBottomSheetContentSize.width != newSize.width || TiBottomSheetContentSize.height != newSize.height){ - if (!CGSizeEqualToSize([viewController preferredContentSize], newSize)) { - // NSLog(@"proxyDidRelayout "); - [self updateContentSize]; - } - } - } - } + TiThreadPerformOnMainThread( + ^{ + if (sender == contentViewProxy) { + if (viewController != nil) { + CGSize newSize = [self contentSize:sender]; + if (TiBottomSheetContentSize.width != newSize.width || TiBottomSheetContentSize.height != newSize.height){ + if (!CGSizeEqualToSize([viewController preferredContentSize], newSize)) { + [self updateContentSize]; + } + } + } + } + }, + NO); + } - (void)sheetPresentationControllerDidChangeSelectedDetentIdentifier :(UISheetPresentationController *)bottomSheetPresentationController { - - // NSLog(@"\n\n sheetPresentationControllerDidChangeSelectedDetentIdentifier "); - if (bottomSheetPresentationController.selectedDetentIdentifier == UISheetPresentationControllerDetentIdentifierMedium){ NSDictionary *detentObject = [NSDictionary dictionaryWithObjectsAndKeys:@"medium", @"selectedDetentIdentifier", nil]; [self fireEvent:@"detentChange" withObject:detentObject]; @@ -1185,13 +1199,8 @@ - (void)sheetPresentationControllerDidChangeSelectedDetentIdentifier :(UISheetPr } - - (BOOL)presentationControllerShouldDismiss:(UISheetPresentationController *)bottomSheetPresentationController { - - // NSLog(@"presentationControllerShouldDismiss "); - - if ([[self viewController] presentedViewController] != nil) { return NO; } @@ -1203,18 +1212,13 @@ - (BOOL)presentationControllerShouldDismiss:(UISheetPresentationController *)bot - (void)presentationControllerDidDismiss:(UISheetPresentationController *)bottomSheetPresentationController { - // NSLog(@"presentationControllerDidDismiss "); - // DebugLog(@"BottomSheet presentationControllerDidDismiss"); [bottomSheetModule cleanup]; if (eventFired == NO){ eventFired = YES; [self fireEvent:@"closed" withObject:nil]; } - currentTiBottomSheet = nil; - - // [self cleanup]; } - (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context @@ -1239,115 +1243,10 @@ - (void)deviceRotated:(NSNotification *)sender { deviceRotated = YES; } - - - @end -@implementation ContentScrollView -// -//- (UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event -//{ -// UIView *hitView = [super hitTest:point withEvent:event]; -// -// if (hitView == self) { -// return nil; -// } -// return hitView; -//} - -//- (BOOL)gestureRecognizer:(UIPanGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIPanGestureRecognizer *)otherGestureRecognizer -//{ -// NSLog(@"gestureRecognizer: %f ",self.contentOffset.y); -// -//// -//// if (self.scrollEnabled == YES){ -//// -//// if (self.contentOffset.y < 0) { -//// -//// self.scrollEnabled = NO; -//// -//// //self.contentOffset = CGPointZero; -//// // if (self.scrollEnabled == YES){ -//// // self.scrollEnabled = NO; -//// // } -//// NSLog(@"gestureRecognizer should pan"); -//// return NO; -//// -//// -//// // scrollView.userInteractionEnabled = NO; -//// // scrollView.panGestureRecognizer.enabled = NO; -//// } -//// else { -//// // if (self.scrollEnabled == NO){ -//// self.scrollEnabled = YES; -//// // } -//// NSLog(@"gestureRecognizer should NOT pan"); -//// return NO; -//// -//// -//// } -//// -//// } -// if (self.contentOffset.y == 0) { -// return YES; -// } -// else { -// return NO; -// } -// -//} -//- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer -//{ -// if (_panRecognizer == gestureRecognizer) { -// if ([otherGestureRecognizer.view isKindOfClass:UIScrollView.class]) { -// UIScrollView *scrollView = (UIScrollView *)otherGestureRecognizer.view; -// if (scrollView.contentOffset.x == 0) { -// return YES; -// } -// } -// } -// -// return NO; -//} -//- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer -//{ -// //NSLog(@"gestureRecognizer "); -// if (self.contentOffset.y <= 0 && self.panGestureRecognizer.enabled == YES) { -// self.panGestureRecognizer.enabled = NO; -// // NSLog(@"gestureRecognizer disabled"); -// } -// // [customBottomSheet panFromScrollView:YES]; -// -//// if (self.contentOffset.y <= 0) { -//// -//// NSLog(@"panRecognizer offset.y <= 0"); -//// return YES; -//// -//// } -//// else { -//// NSLog(@"panRecognizer offset.y > 0"); -//// -//// return NO; -//// } -// return YES; -// -//// NSLog(@"gestureRecognizer %@",gestureRecognizer.state); -// // NSLog(@"otherGestureRecognizer %@",otherGestureRecognizer.state); -// -// -//// if (self.dismissing == YES){ -//// NSLog(@"gestureRecognizer YES"); -//// return YES; -//// } -//// else { -//// NSLog(@"gestureRecognizer NO"); -//// -//// return NO; -//// } -//// return YES; -//} +@implementation ContentScrollView @end diff --git a/ios/manifest b/ios/manifest index 1f8705e..5354ff8 100755 --- a/ios/manifest +++ b/ios/manifest @@ -2,7 +2,7 @@ # this is your module manifest and used by Titanium # during compilation, packaging, distribution, etc. # -version: 1.0.1 +version: 1.0.3 apiversion: 2 architectures: arm64 x86_64 mac: false diff --git a/ios/ti.bottomsheetcontroller.xcodeproj/project.xcworkspace/xcuserdata/marcbender.xcuserdatad/UserInterfaceState.xcuserstate b/ios/ti.bottomsheetcontroller.xcodeproj/project.xcworkspace/xcuserdata/marcbender.xcuserdatad/UserInterfaceState.xcuserstate index 763d513..a251795 100755 Binary files a/ios/ti.bottomsheetcontroller.xcodeproj/project.xcworkspace/xcuserdata/marcbender.xcuserdatad/UserInterfaceState.xcuserstate and b/ios/ti.bottomsheetcontroller.xcodeproj/project.xcworkspace/xcuserdata/marcbender.xcuserdatad/UserInterfaceState.xcuserstate differ