Skip to content

Commit

Permalink
Update to 1.1.0
Browse files Browse the repository at this point in the history
added width property (DIP) for bottomSheet (nonSystemSheet)
added top property for tableView/listView/scrollView as contentView
  • Loading branch information
mbender74 committed Jan 26, 2022
1 parent ed65ac3 commit ffa8f33
Show file tree
Hide file tree
Showing 9 changed files with 169 additions and 26 deletions.
4 changes: 3 additions & 1 deletion ios/Classes/BottomSheetViewController.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ typedef enum State {
}State;


@interface BottomSheetViewController : UIViewController {
@interface BottomSheetViewController : UIViewController <UIGestureRecognizerDelegate> {

enum State maxState;
CGFloat maxPosition;
Expand Down Expand Up @@ -57,6 +57,8 @@ UIScrollView *customSheetScrollView;
UIView *customView;
CGRect windowRect;
UIPanGestureRecognizer *thisGesture;
UITapGestureRecognizer *thisTapGesture;

UIEdgeInsets safeAreaInset;

}
Expand Down
62 changes: 56 additions & 6 deletions ios/Classes/BottomSheetViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,9 @@ - (void)viewDidLoad {
self.fullViewYPosition = _fullViewYPosition;
self.partialViewYPosition = _partialViewYPosition;
self.expandedViewYPosition = _expandedViewYPosition;

customView = [myParentProxy contentViewOfSheet];
windowRect = customView.frame;

[self setupData];
[self setupGestureEvent];
}
Expand All @@ -93,8 +95,6 @@ - (void)viewDidAppear:(BOOL)animated {
__weak __typeof(self)weakSelf = self;


customView = [myParentProxy contentViewOfSheet];
windowRect = customView.frame;
director = up;

[UIView animateWithDuration:0.35 delay:0 usingSpringWithDamping:1 initialSpringVelocity:1 options:UIViewAnimationOptionCurveEaseOut animations:^{
Expand Down Expand Up @@ -437,6 +437,14 @@ - (UIPanGestureRecognizer *)panRecognizer {
- (void)setupGestureEvent {
UIPanGestureRecognizer *gesture = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(panGesture:)];
[self.view addGestureRecognizer:gesture];

UITapGestureRecognizer *singleFingerTap =
[[UITapGestureRecognizer alloc] initWithTarget:self
action:@selector(handleSingleTap:)];
[self.view addGestureRecognizer:singleFingerTap];
thisTapGesture = singleFingerTap;
singleFingerTap.delegate = self;

thisGesture = gesture;
[self roundViews];
}
Expand Down Expand Up @@ -497,6 +505,9 @@ - (void)moveViewWithGesture:(UIPanGestureRecognizer *)recognizer {
doNotDismiss = YES;
}
CGPoint translation = [recognizer translationInView:self.view];
CGPoint location = [recognizer locationInView:self.view];
doNotTranslate = NO;

if(panInit == YES){
panInit = NO;
translation.y = 0;
Expand All @@ -505,8 +516,11 @@ - (void)moveViewWithGesture:(UIPanGestureRecognizer *)recognizer {
dismissModeOfSheet = NO;
CGFloat newY = minY + translation.y;

doNotTranslate = NO;

if (location.x < customView.superview.frame.origin.x || location.x > (customView.superview.frame.origin.x + customView.superview.frame.size.width)){
doNotTranslate = YES;
return;
}

if (doNotDismiss == YES){
if (newY > maxPosition) {
if (newY < minPosition){
Expand Down Expand Up @@ -613,10 +627,27 @@ - (void)lastContentOffsetY:(CGFloat)contentOffsetY{
newSrollViewOffsetY = contentOffsetY;
}

- (void)handleSingleTap:(UITapGestureRecognizer *)recognizer {


CGPoint locationInSheet = [recognizer locationInView:self.view];

if ([TiUtils boolValue:[myParentProxy valueForUndefinedKey:@"nonSystemSheetDisableDimmedBackgroundTouchDismiss"] def:NO] == NO){
if (locationInSheet.x < customView.superview.frame.origin.x || locationInSheet.x > customView.superview.frame.origin.x+customView.superview.frame.size.width){
dismissModeOfSheet = YES;
[myParentProxy sendEvent:@"dismiss"];
[myParentProxy fireEvent:@"dismissing" withObject:nil];
return;
}

}
}

- (void)panGesture:(UIPanGestureRecognizer *)recognizer {


CGPoint translation = [recognizer translationInView:self.view];

[self moveViewWithGesture:recognizer];

if (recognizer.state != UIGestureRecognizerStateEnded) {
Expand Down Expand Up @@ -865,4 +896,23 @@ - (void)panGesture:(UIPanGestureRecognizer *)recognizer {
}
}


- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch
{
CGPoint location = [touch locationInView:self.view];

if (CGRectContainsPoint(customView.superview.frame, location)) {
if (gestureRecognizer == thisTapGesture){
return NO;
}
return YES;
}
return YES;
}

- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer{

return YES;
}

@end
2 changes: 2 additions & 0 deletions ios/Classes/TiBottomsheetcontrollerProxy.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
BOOL nonSystemSheetShouldScroll;
BOOL nonSystemSheetAutomaticStartPositionFromContentViewHeight;
BOOL eventFired;
BOOL addScrollInsetTop;
BOOL useNavController;
BOOL defaultsToNonSystemSheet;
BOOL contentViewScrollingDisabled;
Expand All @@ -46,6 +47,7 @@
NSString *lastDetentStatus;
UIView *backgroundView;
CGFloat realContentHeight;
CGFloat additionalBottomInset;
CGFloat scrollableContentHeight;
UIEdgeInsets bottomSheetSafeAreaInset;
TiViewProxy *contentViewProxy;
Expand Down
118 changes: 104 additions & 14 deletions ios/Classes/TiBottomsheetcontrollerProxy.m
Original file line number Diff line number Diff line change
Expand Up @@ -465,7 +465,8 @@ - (void)cleanup
bottomSheetInitialized = NO;
eventFired = NO;
bottomSheet.delegate = nil;

addScrollInsetTop = NO;
additionalBottomInset = 0;
myScrollView = nil;
backgroundView = nil;
customBottomSheet = nil;
Expand Down Expand Up @@ -770,7 +771,9 @@ - (void)updatePopoverNow
[self replaceValue:[TiUtils hexColorValue:[UIColor lightGrayColor]] forKey:@"backgroundColor" notification:YES];
}
currentTiBottomSheet = self;

addScrollInsetTop = YES;
additionalBottomInset = 0;

if (defaultsToNonSystemSheet == NO){

UIViewController *theController = [self viewController];
Expand Down Expand Up @@ -913,23 +916,65 @@ - (void)updatePopoverNow
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;
CGFloat y = [[[TiApp app] controller] topPresentedController].view.frame.origin.y;
CGFloat height = [[[TiApp app] controller] topPresentedController].view.frame.size.height;
CGFloat width = [[[TiApp app] controller] topPresentedController].view.frame.size.width;
CGFloat controllerWidth = [[[TiApp app] controller] topPresentedController].view.frame.size.width;

CGFloat left = 0;
CGFloat right = 0;

id widthValue = [self valueForUndefinedKey:@"width"];
if (widthValue != nil){
TiDimension widthOfSheet = [TiUtils dimensionValue:widthValue];

if (TiDimensionIsDip(widthOfSheet)) {
if(widthOfSheet.value < controllerWidth){
width = widthOfSheet.value;
}
}
}
id leftValue = [self valueForUndefinedKey:@"left"];
if (leftValue != nil){
TiDimension leftOfSheet = [TiUtils dimensionValue:leftValue];

if (TiDimensionIsDip(leftOfSheet)) {
left = leftOfSheet.value;
}
}
id rightValue = [self valueForUndefinedKey:@"right"];
if (rightValue != nil){
TiDimension rightOfSheet = [TiUtils dimensionValue:rightValue];

if (TiDimensionIsDip(rightOfSheet)) {
right = rightOfSheet.value;
}
}

CGFloat sheetOriginX = 0;
sheetOriginX = (controllerWidth/2) - (width/2);
if (left > 0){
sheetOriginX = left;
}
if (right > 0){
sheetOriginX = controllerWidth - width - right;
}


if ([TiUtils boolValue:[self valueForUndefinedKey:@"nonSystemSheetDisableDimmedBackground"] def:NO] == NO){
backgroundView = [[UIView alloc] init];
backgroundView.frame = CGRectMake( 0, 0, width, height);
backgroundView.frame = CGRectMake( 0, 0, controllerWidth, height);

if ([TiUtils boolValue:[self valueForUndefinedKey:@"nonSystemSheetDisableDimmedBackgroundTouchDismiss"] def:NO] == NO){
UITapGestureRecognizer *singleFingerTap =
[[UITapGestureRecognizer alloc] initWithTarget:self
action:@selector(handleSingleTap:)];
[backgroundView addGestureRecognizer:singleFingerTap];

}
}



customBottomSheet.view.frame = CGRectMake( 0, y + height, width, height);

containerView = [[UIView alloc] init];
Expand Down Expand Up @@ -967,7 +1012,7 @@ - (void)updatePopoverNow
else {
heightOfContainer = customBottomSheet.view.frame.size.height;
}
containerView.frame = CGRectMake( 0, 0, widthOfContainer, heightOfContainer);
containerView.frame = CGRectMake( sheetOriginX, 0, widthOfContainer, heightOfContainer);

CGRect controllerViewFrame = CGRectMake( 0, 0, widthOfContainer, heightOfContainer);
if (nonSystemSheetShouldScroll == YES){
Expand All @@ -988,6 +1033,7 @@ - (void)updatePopoverNow
else {
scrollableContentHeight = realContentHeight;
}

}
[contentViewOfSheet setFrame:controllerViewFrame];

Expand Down Expand Up @@ -1039,6 +1085,17 @@ - (void)updatePopoverNow
}
}

id topValue = [contentViewProxy valueForKey:@"top"];

TiDimension top = [TiUtils dimensionValue:topValue];

if (TiDimensionIsDip(top)) {
controllerViewFrame.origin.y = controllerViewFrame.origin.y + top.value;
controllerViewFrame.size.height = controllerViewFrame.size.height + top.value;
addScrollInsetTop = NO;
additionalBottomInset = top.value;
}

[contentViewOfSheet setFrame:controllerViewFrame];
[containerView addSubview:contentViewOfSheet];
[self scrollingInsets:contentViewOfSheet];
Expand Down Expand Up @@ -1101,6 +1158,7 @@ - (void)updatePopoverNow
[closeButtonView setCenter:CGPointMake((containerView.frame.size.width - (closeButtonView.bounds.size.width/2)), 24)];
[containerView insertSubview:closeButtonView aboveSubview:handleContainer];
}

if (backgroundView != nil){
[[[[TiApp app] controller] topPresentedController].view addSubview:backgroundView];
[[[[TiApp app] controller] topPresentedController].view insertSubview:customBottomSheet.view aboveSubview:backgroundView];
Expand All @@ -1112,6 +1170,10 @@ - (void)updatePopoverNow

}





- (UIColor *)adaptiveGrabberColor
{
// #5a5a5f
Expand All @@ -1128,37 +1190,46 @@ - (void)scrollingInsets:(UIView *)view
if ([view respondsToSelector:@selector(setScrollEnabled:)] && self.insetsDone == NO){

CGFloat bottomInset = 0;
CGFloat scrollInsetTop = 0;
if (addScrollInsetTop == YES){
scrollInsetTop = 20;
}


if (self.fixedHeight == NO){
bottomInset = bottomSheetSafeAreaInset.bottom;
bottomInset = bottomSheetSafeAreaInset.bottom + additionalBottomInset;
}

if ([view isKindOfClass:[UITableView class]]){

if (nonSystemSheetAutomaticStartPositionFromContentViewHeight == YES){
bottomInset = bottomSheetSafeAreaInset.bottom;
bottomInset = bottomSheetSafeAreaInset.bottom + additionalBottomInset;

// 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 setScrollIndicatorInsets:UIEdgeInsetsMake(scrollInsetTop, 0, bottomInset, 0)];
[(UITableView *)view setAlwaysBounceVertical:NO];


CGFloat topInset = [(UITableView *)view contentInset].top;

[(UITableView *)view setContentInset:UIEdgeInsetsMake(0, 0, bottomInset, 0)];
self.insetsDone = YES;
}
else if ([view isKindOfClass:[UIScrollView class]]){
if (nonSystemSheetAutomaticStartPositionFromContentViewHeight == YES){
bottomInset = bottomSheetSafeAreaInset.bottom;
bottomInset = bottomSheetSafeAreaInset.bottom + additionalBottomInset;

// CGRect newFrame = [(UIScrollView *)view frame];
// newFrame.size.height = newFrame.size.height + bottomSheetSafeAreaInset.bottom;
// [(UIScrollView *)view setFrame:newFrame];
}
[(UIScrollView *)view setAlwaysBounceVertical:NO];
CGFloat topInset = [(UIScrollView *)view contentInset].top;

[(UIScrollView *)view setScrollIndicatorInsets:UIEdgeInsetsMake(20, 0, bottomInset, 0)];
[(UIScrollView *)view setScrollIndicatorInsets:UIEdgeInsetsMake(scrollInsetTop, 0, bottomInset, 0)];
[(UIScrollView *)view setContentInset:UIEdgeInsetsMake(0, 0, bottomInset, 0)];
self.insetsDone = YES;
}
Expand All @@ -1178,13 +1249,16 @@ - (void)scrollingInsets:(UIView *)view
- (void)handleSingleTap:(UITapGestureRecognizer *)recognizer
{
CGPoint location = [recognizer locationInView:[recognizer.view superview]];

if (isDismissing == NO){
isDismissing = YES;
[self close:nil];
}
}




- (void)handleSingleHandleTap:(UITapGestureRecognizer *)recognizer
{
NSDictionary *userDetents = [self valueForKey:@"detents"];
Expand Down Expand Up @@ -1414,6 +1488,22 @@ - (void)deviceRotated:(NSNotification *)sender
{
deviceRotated = YES;
}



- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch {
if (customBottomSheet != nil){
if ([customBottomSheet.view hitTest:[touch locationInView:contentViewProxy.view] withEvent:nil]) {
return NO;
}
}
return YES;
}
- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer{
return YES;
}


@end


4 changes: 2 additions & 2 deletions ios/manifest
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
# this is your module manifest and used by Titanium
# during compilation, packaging, distribution, etc.
#
version: 1.0.9
version: 1.1.0
apiversion: 2
architectures:arm64 x86_64
mac: false
mac: true
description: ti.bottomsheetcontroller
author: Marc Bender
license: free for everyone, no license (code partly taken from Titanium SDK)
Expand Down
Loading

0 comments on commit ffa8f33

Please sign in to comment.