Skip to content

Commit 09ab3a1

Browse files
author
farfromrefuge
committed
feat(bottomsheet): backgroundOpacity option
1 parent 6e285ae commit 09ab3a1

File tree

3 files changed

+15
-4
lines changed

3 files changed

+15
-4
lines changed

src/bottomsheet/bottomsheet-common.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ export interface BottomSheetOptions {
3737
closeCallback?: Function; // A function that will be called when the view is closed. Any arguments provided when calling shownInBottomSheet.closeCallback will be available here.
3838
trackingScrollView?: string; // optional id of the scroll view to track
3939
transparent?: boolean; // optional parameter to make the bottomsheet transparent
40+
backgroundOpacity?: number; // optional parameter to make the bottomsheet background semi transparent
4041
ignoreTopSafeArea?: boolean; // optional ios parameter to top safe area. Default is true
4142
ignoreBottomSafeArea?: boolean; // optional ios parameter to bottom safe area. Default is false
4243
disableDimBackground?: boolean; // optional parameter to remove the dim background

src/bottomsheet/bottomsheet.android.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,6 @@ export class ViewWithBottomSheet extends ViewWithBottomSheetBase {
7575
this._bottomSheetFragment = null;
7676
}
7777

78-
7978
protected _showNativeBottomSheet(parent: View, options: BottomSheetOptions) {
8079
this._commonShowNativeBottomSheet(parent, options);
8180
const owner = this;
@@ -153,7 +152,6 @@ export class ViewWithBottomSheet extends ViewWithBottomSheetBase {
153152
},
154153

155154
onStart(fragment: com.nativescript.material.bottomsheet.BottomSheetDialogFragment): void {
156-
const color = owner.backgroundColor;
157155
const contentViewId = getId('design_bottom_sheet');
158156
const view = fragment.getDialog().findViewById(contentViewId);
159157
const transparent = bottomSheetOptions.options?.transparent === true;
@@ -162,6 +160,13 @@ export class ViewWithBottomSheet extends ViewWithBottomSheetBase {
162160
setTimeout(() => {
163161
view.setBackground(null);
164162
}, 0);
163+
} else if (bottomSheetOptions.options?.backgroundOpacity) {
164+
// we need delay it just a bit or it wont work
165+
setTimeout(() => {
166+
const backgroundDrawable = view.getBackground();
167+
backgroundDrawable.setAlpha(bottomSheetOptions.options?.backgroundOpacity * 255);
168+
view.setBackground(backgroundDrawable);
169+
}, 0);
165170
}
166171

167172
const behavior = com.google.android.material.bottomsheet.BottomSheetBehavior.from(view);

src/bottomsheet/bottomsheet.ios.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -421,8 +421,13 @@ export class ViewWithBottomSheet extends ViewWithBottomSheetBase {
421421
controller.view.backgroundColor = UIColor.clearColor;
422422
// for it to be prettier let s disable elevation
423423
controller.view['elevation'] = 0;
424-
} else if (!(this instanceof Page)) {
425-
controller.view.backgroundColor = majorVersion <= 12 && !UIColor.systemBackgroundColor ? UIColor.whiteColor : UIColor.systemBackgroundColor;
424+
} else {
425+
if (!(this instanceof Page)) {
426+
controller.view.backgroundColor = majorVersion <= 12 && !UIColor.systemBackgroundColor ? UIColor.whiteColor : UIColor.systemBackgroundColor;
427+
}
428+
if (options.backgroundOpacity) {
429+
controller.view.backgroundColor = controller.view.backgroundColor.colorWithAlphaComponent(options.backgroundOpacity);
430+
}
426431
}
427432
const transitionCoordinator = bottomSheet.transitionCoordinator;
428433
if (transitionCoordinator) {

0 commit comments

Comments
 (0)