Skip to content

Commit

Permalink
fixed multiple instances of the bottomSheetController
Browse files Browse the repository at this point in the history
added new property for nonSystemSheet
  • Loading branch information
mbender74 committed Nov 13, 2021
1 parent bc7d62b commit 478522e
Show file tree
Hide file tree
Showing 9 changed files with 241 additions and 173 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,8 @@ Also new features for the nonSystemSheet!

* `nonSystemSheetDisableDimmedBackground:bool`<br/>(optional) when set true, disables the dimmed backgroundView of the sheetcontroller

* `nonSystemSheetDisableDimmedBackgroundTouchDismiss:bool`<br/>(optional) when set true, disables the touch event on the dimmed backgroundView that will close the sheetController

* `nonSystemSheetDisablePanGestureDismiss:bool`<br/>(optional) when set true, disables the pan gesture (drag down to close), closing is only possible via closeButton then OR via "close" method

## Example
Expand Down
76 changes: 41 additions & 35 deletions ios/Classes/BottomSheetViewController.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,8 @@
//

#import <UIKit/UIKit.h>
#import "TiBottomsheetcontrollerProxy.h"

NS_ASSUME_NONNULL_BEGIN

typedef enum Director {
up,
down,
Expand All @@ -22,39 +20,47 @@ typedef enum State {
full,
dismiss
}State;
static State maxState = full;
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;
static CGFloat expandedViewYPosition = 0;
static bool dismissModeOfSheet = NO;
static bool doNotTranslate = NO;
static bool backgroundViewHidden = NO;
static UIColor *viewBackgroundColor = nil;
static UIColor *dimmedViewBackgroundColor = nil;
static NSString *largestUndimmedDetent = nil;
static NSString *startDetent = nil;
static NSString *detentString = nil;
static Director director = up;
@interface BottomSheetViewController : UIViewController


@interface BottomSheetViewController : UIViewController {

enum State maxState;
CGFloat maxPosition;
enum State minState;
CGFloat minPosition;
UIEdgeInsets insets;
UIEdgeInsets scrollBarinsets;
bool panEnabled;
bool panInit;
bool panFromScrollView;
CGFloat width;
CGFloat height;
CGRect customViewRect;
bool fullPositon;
bool mediumPosition;
bool smallPosition;
CGFloat lastScrollViewOffsetY;
CGFloat newSrollViewOffsetY;
CGFloat lastTranslation;
CGFloat yPosition;
NSDictionary *userDetents;
bool dismissModeOfSheet;
bool doNotTranslate;
bool backgroundViewHidden;
UIColor *viewBackgroundColor;
UIColor *dimmedViewBackgroundColor;
NSString *largestUndimmedDetent;
NSString *startDetent;
NSString *detentString ;
Director director;
UIScrollView *customSheetScrollView;
UIView *customView;
CGRect windowRect;
UIPanGestureRecognizer *thisGesture;
UIEdgeInsets safeAreaInset;

}

@property (assign, nonatomic) State lastStatus;
@property (assign, nonatomic) NSString *selectedDetentIdentifier;
@property (assign, nonatomic) CGFloat fullViewYPosition;
Expand Down
121 changes: 76 additions & 45 deletions ios/Classes/BottomSheetViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -7,32 +7,36 @@
//

#import "BottomSheetViewController.h"
#import "TiBottomsheetcontrollerProxy.h"


@interface BottomSheetViewController ()

@interface BottomSheetViewController (){
TiBottomsheetcontrollerProxy *myParentProxy;
}

@end

@implementation BottomSheetViewController


#pragma mark Public APIs

TiBottomsheetcontrollerProxy *myParentProxy;
UIScrollView *customSheetScrollView;
UIView *customView;
CGRect windowRect;
#pragma mark Public APIs

UIPanGestureRecognizer *thisGesture;
UIEdgeInsets safeAreaInset;

-(id)proxyOfBottomSheetController
{
return myParentProxy;
if (myParentProxy != nil){
return myParentProxy;
}
else {
return nil;
}
}
-(void)setProxyOfBottomSheetController:(id)args
{
if (myParentProxy != nil){
myParentProxy = nil;
}
myParentProxy = args;
}

Expand All @@ -43,13 +47,40 @@ -(void)setProxyOfBottomSheetController:(id)args
- (void)viewDidLoad {
[super viewDidLoad];

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;
maxState = full;
maxPosition = 0;
minState = partial;
minPosition = 0;
panEnabled = YES;
panInit = NO;
panFromScrollView = NO;
width = 0;
height = 0;
customViewRect;
fullPositon = YES;
mediumPosition = YES;
smallPosition = YES;
lastScrollViewOffsetY = 0;
newSrollViewOffsetY = 0;
lastTranslation = 0;
yPosition = 0;
dismissModeOfSheet = NO;
doNotTranslate = NO;
backgroundViewHidden = NO;
viewBackgroundColor = nil;
dimmedViewBackgroundColor = nil;
largestUndimmedDetent = nil;
startDetent = nil;
detentString = nil;
director = up;
_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];
Expand All @@ -73,12 +104,12 @@ - (void)viewDidAppear:(BOOL)animated {
[weakSelf moveView:weakSelf.lastStatus fromEvent:NO];
} completion:^(BOOL finished) {

CGFloat startY = fullViewYPosition;
CGFloat startY = _fullViewYPosition;

if (self.lastStatus == partial) {
startY = partialViewYPosition;
startY = _partialViewYPosition;
} else if (self.lastStatus == expanded) {
startY = expandedViewYPosition;
startY = _expandedViewYPosition;
}
customView = [myParentProxy contentViewOfSheet];
windowRect = customView.frame;
Expand Down Expand Up @@ -129,9 +160,9 @@ - (void)setupData {
self.fullViewYPosition = [UIScreen mainScreen].bounds.size.height - [TiUtils intValue:[myParentProxy valueForKey:@"nonSystemSheetLargeHeight"]];
}

fullViewYPosition = self.fullViewYPosition;
partialViewYPosition = self.partialViewYPosition;
expandedViewYPosition = self.expandedViewYPosition;
_fullViewYPosition = self.fullViewYPosition;
_partialViewYPosition = self.partialViewYPosition;
_expandedViewYPosition = self.expandedViewYPosition;

width = self.view.frame.size.width;
height = self.view.frame.size.height;
Expand All @@ -141,10 +172,10 @@ - (void)setupData {
safeAreaInset = [[topContainerController hostingView] safeAreaInsets];


maxPosition = fullViewYPosition;
maxPosition = _fullViewYPosition;
maxState = full;

minPosition = partialViewYPosition;
minPosition = _partialViewYPosition;
minState = partial;

if ([myParentProxy valueForKey:@"startDetent"]){
Expand All @@ -158,19 +189,19 @@ - (void)setupData {
userDetents = [myParentProxy valueForKey:@"detents"];

if ([TiUtils boolValue:[userDetents valueForKey:@"large"] def:YES]){
maxPosition = fullViewYPosition;
maxPosition = _fullViewYPosition;
maxState = full;
if (![TiUtils boolValue:[userDetents valueForKey:@"small"] def:YES] && ![TiUtils boolValue:[userDetents valueForKey:@"medium"] def:YES]){
mediumPosition = NO;
smallPosition = NO;

minPosition = fullViewYPosition;
minPosition = _fullViewYPosition;
minState = full;
startDetent = @"large";
}
else {
if (![TiUtils boolValue:[userDetents valueForKey:@"small"] def:YES] && [TiUtils boolValue:[userDetents valueForKey:@"medium"] def:YES]){
minPosition = expandedViewYPosition;
minPosition = _expandedViewYPosition;
minState = expanded;
smallPosition = NO;

Expand All @@ -188,12 +219,12 @@ - (void)setupData {
}
}
else if ([TiUtils boolValue:[userDetents valueForKey:@"medium"] def:YES]){
maxPosition = expandedViewYPosition;
maxPosition = _expandedViewYPosition;
maxState = expanded;
fullPositon = NO;

if (![TiUtils boolValue:[userDetents valueForKey:@"small"] def:YES]){
minPosition = expandedViewYPosition;
minPosition = _expandedViewYPosition;
minState = expanded;
smallPosition = NO;

Expand All @@ -208,7 +239,7 @@ - (void)setupData {
}
}
else if ([TiUtils boolValue:[userDetents valueForKey:@"small"] def:YES]){
maxPosition = partialViewYPosition;
maxPosition = _partialViewYPosition;
maxState = partial;
mediumPosition = NO;
fullPositon = NO;
Expand All @@ -218,7 +249,7 @@ - (void)setupData {
}
}
else {
maxPosition = fullViewYPosition;
maxPosition = _fullViewYPosition;
maxState = full;
}
}
Expand All @@ -229,10 +260,10 @@ - (void)setupData {
//realHeight = [myParentProxy realContentHeight] + safeAreaInset.bottom;
realHeight = [myParentProxy realContentHeight];

fullViewYPosition = [UIScreen mainScreen].bounds.size.height - realHeight;
_fullViewYPosition = [UIScreen mainScreen].bounds.size.height - realHeight;

maxPosition = fullViewYPosition;
minPosition = fullViewYPosition;
maxPosition = _fullViewYPosition;
minPosition = _fullViewYPosition;
maxState = full;
minState = full;
mediumPosition = NO;
Expand Down Expand Up @@ -412,16 +443,16 @@ - (void)setupGestureEvent {

- (void)moveView:(State)state fromEvent:(bool)tapEvent {

yPosition = fullViewYPosition;
yPosition = _fullViewYPosition;

if (dismissModeOfSheet == NO){
if (state == partial) {
yPosition = partialViewYPosition;
yPosition = _partialViewYPosition;
} else if (state == expanded) {
yPosition = expandedViewYPosition;
yPosition = _expandedViewYPosition;
}
else {
yPosition = fullViewYPosition;
yPosition = _fullViewYPosition;
}
}
else {
Expand Down Expand Up @@ -477,8 +508,8 @@ - (void)moveViewWithGesture:(UIPanGestureRecognizer *)recognizer {
doNotTranslate = NO;

if (doNotDismiss == YES){
if (newY >= maxPosition) {
if (newY <= minPosition){
if (newY > maxPosition) {
if (newY < minPosition){
width = self.view.frame.size.width;
height = self.view.frame.size.height;
const CGRect rect = CGRectMake(0 , newY, width, height);
Expand Down Expand Up @@ -521,7 +552,7 @@ - (void)moveViewWithGesture:(UIPanGestureRecognizer *)recognizer {
}

else {
if ((newY >= maxPosition)) {
if ((newY > maxPosition)) {
width = self.view.frame.size.width;
height = self.view.frame.size.height;
const CGRect rect = CGRectMake(0 , newY, width, height);
Expand Down Expand Up @@ -658,13 +689,13 @@ - (void)panGesture:(UIPanGestureRecognizer *)recognizer {
if (recognizer.view) {
if (state == expanded) {
CGFloat endLocation = recognizer.view.frame.origin.y;
if (endLocation > expandedViewYPosition &&
if (endLocation > _expandedViewYPosition &&
director == down && smallPosition) {
state = partial;

} else if (endLocation < expandedViewYPosition &&
} else if (endLocation < _expandedViewYPosition &&
director == up && fullPositon) {
if (maxPosition == fullViewYPosition){
if (maxPosition == _fullViewYPosition){
state = full;
}
else {
Expand All @@ -675,7 +706,7 @@ - (void)panGesture:(UIPanGestureRecognizer *)recognizer {
} else if (state == partial &&
weakSelf.lastStatus == partial) {
CGFloat endLocation = recognizer.view.frame.origin.y;
if (endLocation < expandedViewYPosition && mediumPosition) {
if (endLocation < _expandedViewYPosition && mediumPosition) {
state = expanded;
}
else {
Expand Down
8 changes: 4 additions & 4 deletions ios/Classes/TiBottomsheetcontrollerModule.m
Original file line number Diff line number Diff line change
Expand Up @@ -56,13 +56,13 @@ -(void)didReceiveMemoryWarning:(NSNotification*)notification
// reloaded once memory is available - such as caches
[super didReceiveMemoryWarning:notification];
}


#pragma mark Public API

- (id)createBottomSheet:(id)args{
id myBottomSheet = [[TiBottomsheetcontrollerProxy alloc] _initWithPageContext:[self executionContext] args:args];
return myBottomSheet;
// return [[TiBottomsheetcontrollerProxy alloc] _initWithPageContext:[self executionContext] args:args];
return [[TiBottomsheetcontrollerProxy alloc] _initWithPageContext:[self executionContext] args:args];
}



@end
Loading

0 comments on commit 478522e

Please sign in to comment.