@nativescript-community/ui-bottomsheet 0.0.0-stage → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +16 -0
- package/LICENSE +201 -0
- package/README.md +213 -2
- package/index-common.d.ts +93 -0
- package/index-common.js +140 -0
- package/index-common.js.map +1 -0
- package/index.android.d.ts +44 -0
- package/index.android.js +475 -0
- package/index.android.js.map +1 -0
- package/index.d.ts +100 -0
- package/index.ios.d.ts +57 -0
- package/index.ios.js +310 -0
- package/index.ios.js.map +1 -0
- package/ios-layout.d.ts +34 -0
- package/ios-layout.js +267 -0
- package/ios-layout.js.map +1 -0
- package/package.json +49 -5
- package/platforms/android/include.gradle +6 -0
- package/platforms/android/java/com/nativescript/ui/bottomsheet/BottomSheetDialog.java +38 -0
- package/platforms/android/java/com/nativescript/ui/bottomsheet/BottomSheetDialogFragment.java +73 -0
- package/platforms/android/native-api-usage.json +34 -0
- package/platforms/ios/native-api-usage.json +11 -0
- package/svelte/index.d.ts +24 -0
- package/svelte/index.js +48 -0
- package/svelte/index.js.map +1 -0
- package/tsconfig.tsbuildinfo +1 -0
package/ios-layout.js
ADDED
|
@@ -0,0 +1,267 @@
|
|
|
1
|
+
import { Application, IOSHelper, Screen, Trace, Utils, View } from '@nativescript/core';
|
|
2
|
+
const majorVersion = Utils.ios.MajorVersion;
|
|
3
|
+
/**
|
|
4
|
+
* Finds the view controller from which a new sheet/dialog can be presented:
|
|
5
|
+
* the top most presented controller, ignoring alert controllers.
|
|
6
|
+
*/
|
|
7
|
+
export function getPresentingController(parent, rootView = Application.getRootView()) {
|
|
8
|
+
if (rootView.parent) {
|
|
9
|
+
rootView = rootView.parent;
|
|
10
|
+
}
|
|
11
|
+
const currentView = parent.modal || parent;
|
|
12
|
+
let parentController = currentView.viewController;
|
|
13
|
+
if (!parentController.presentedViewController && rootView.viewController.presentedViewController) {
|
|
14
|
+
parentController = rootView.viewController.presentedViewController;
|
|
15
|
+
}
|
|
16
|
+
while (parentController.presentedViewController) {
|
|
17
|
+
while (parentController.presentedViewController instanceof UIAlertController ||
|
|
18
|
+
(parentController.presentedViewController['isAlertController'] && parentController.presentedViewController.presentedViewController)) {
|
|
19
|
+
parentController = parentController.presentedViewController;
|
|
20
|
+
}
|
|
21
|
+
if (parentController.presentedViewController instanceof UIAlertController || parentController.presentedViewController['isAlertController']) {
|
|
22
|
+
break;
|
|
23
|
+
}
|
|
24
|
+
else {
|
|
25
|
+
parentController = parentController.presentedViewController;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
return parentController;
|
|
29
|
+
}
|
|
30
|
+
function initLayoutGuide(controller) {
|
|
31
|
+
const rootView = controller.view;
|
|
32
|
+
const layoutGuide = UILayoutGuide.alloc().init();
|
|
33
|
+
rootView.addLayoutGuide(layoutGuide);
|
|
34
|
+
NSLayoutConstraint.activateConstraints([
|
|
35
|
+
layoutGuide.topAnchor.constraintEqualToAnchor(controller.topLayoutGuide.bottomAnchor),
|
|
36
|
+
layoutGuide.bottomAnchor.constraintEqualToAnchor(controller.bottomLayoutGuide.topAnchor),
|
|
37
|
+
layoutGuide.leadingAnchor.constraintEqualToAnchor(rootView.leadingAnchor),
|
|
38
|
+
layoutGuide.trailingAnchor.constraintEqualToAnchor(rootView.trailingAnchor)
|
|
39
|
+
]);
|
|
40
|
+
return layoutGuide;
|
|
41
|
+
}
|
|
42
|
+
function layoutView(controller, owner) {
|
|
43
|
+
let layoutGuide = controller.view.safeAreaLayoutGuide;
|
|
44
|
+
if (!layoutGuide) {
|
|
45
|
+
Trace.write(`safeAreaLayoutGuide during layout of ${owner}. Creating fallback constraints, but layout might be wrong.`, Trace.categories.Layout, Trace.messageType.error);
|
|
46
|
+
layoutGuide = initLayoutGuide(controller);
|
|
47
|
+
}
|
|
48
|
+
const safeArea = layoutGuide.layoutFrame;
|
|
49
|
+
let position = IOSHelper.getPositionFromFrame(safeArea);
|
|
50
|
+
const safeAreaSize = safeArea.size;
|
|
51
|
+
const hasChildViewControllers = controller.childViewControllers.count > 0;
|
|
52
|
+
if (hasChildViewControllers) {
|
|
53
|
+
const fullscreen = controller.view.frame;
|
|
54
|
+
position = IOSHelper.getPositionFromFrame(fullscreen);
|
|
55
|
+
}
|
|
56
|
+
const safeAreaWidth = Utils.layout.round(Utils.layout.toDevicePixels(safeAreaSize.width));
|
|
57
|
+
const safeAreaHeight = Utils.layout.round(Utils.layout.toDevicePixels(safeAreaSize.height));
|
|
58
|
+
const widthSpec = Utils.layout.makeMeasureSpec(safeAreaWidth, Utils.layout.EXACTLY);
|
|
59
|
+
const heightSpec = Utils.layout.makeMeasureSpec(Screen.mainScreen.heightPixels, Utils.layout.AT_MOST);
|
|
60
|
+
// reset _cachedFrame or it will wrongly move the view on subsequent layouts
|
|
61
|
+
// (owner as any)._cachedFrame = null;
|
|
62
|
+
View.measureChild(null, owner, widthSpec, heightSpec);
|
|
63
|
+
const marginTop = owner.effectiveMarginTop;
|
|
64
|
+
const marginBottom = owner.effectiveMarginBottom;
|
|
65
|
+
const marginLeft = owner.effectiveMarginLeft + position.left;
|
|
66
|
+
const marginRight = owner.effectiveMarginRight;
|
|
67
|
+
const top = marginTop + position.top;
|
|
68
|
+
const width = Screen.mainScreen.widthPixels;
|
|
69
|
+
const height = owner.getMeasuredHeight();
|
|
70
|
+
View.layoutChild(null, owner, marginLeft, top, width - marginLeft - marginRight, position.top + height + marginBottom);
|
|
71
|
+
const effectiveWidth = width;
|
|
72
|
+
let effectiveHeight = height + top + marginBottom;
|
|
73
|
+
if (controller.ignoreTopSafeArea || controller.ignoreBottomSafeArea) {
|
|
74
|
+
const frame = CGRectMake(Utils.layout.toDeviceIndependentPixels(marginLeft), Utils.layout.toDeviceIndependentPixels(top), Utils.layout.toDeviceIndependentPixels(width), Utils.layout.toDeviceIndependentPixels(height));
|
|
75
|
+
const availableSpace = getAvailableSpaceFromParent(owner, frame);
|
|
76
|
+
if (!availableSpace.fullscreen) {
|
|
77
|
+
// can happen if we get there after the bottomsheet was removed...
|
|
78
|
+
return;
|
|
79
|
+
}
|
|
80
|
+
const startPos = IOSHelper.getPositionFromFrame(frame);
|
|
81
|
+
const fullscreenPosition = IOSHelper.getPositionFromFrame(availableSpace.fullscreen);
|
|
82
|
+
const safeAreaPosition = IOSHelper.getPositionFromFrame(availableSpace.safeArea);
|
|
83
|
+
const adjustedPosition = startPos;
|
|
84
|
+
const orientation = UIDevice.currentDevice.orientation;
|
|
85
|
+
const isLandscape = Application.orientation() === 'landscape';
|
|
86
|
+
// there are still some issues in landscape Right but they seem to come from N
|
|
87
|
+
owner.iosIgnoreSafeArea = true;
|
|
88
|
+
if (controller.ignoreTopSafeArea) {
|
|
89
|
+
const key = 'top';
|
|
90
|
+
const oppositeKey = 'bottom';
|
|
91
|
+
// if (orientation === UIDeviceOrientation.LandscapeLeft) {
|
|
92
|
+
// key = 'left';
|
|
93
|
+
// oppositeKey = 'right';
|
|
94
|
+
// } else if (orientation === UIDeviceOrientation.LandscapeRight) {
|
|
95
|
+
// key = 'right';
|
|
96
|
+
// oppositeKey = 'left';
|
|
97
|
+
// } else if (orientation === UIDeviceOrientation.PortraitUpsideDown) {
|
|
98
|
+
// key = 'bottom';
|
|
99
|
+
// oppositeKey = 'top';
|
|
100
|
+
// }
|
|
101
|
+
const delta = safeAreaPosition[key] - fullscreenPosition[key];
|
|
102
|
+
effectiveHeight -= delta;
|
|
103
|
+
adjustedPosition[oppositeKey] -= delta;
|
|
104
|
+
adjustedPosition[key] -= delta;
|
|
105
|
+
}
|
|
106
|
+
if (controller.ignoreBottomSafeArea) {
|
|
107
|
+
const key = 'bottom';
|
|
108
|
+
// if (orientation === UIDeviceOrientation.LandscapeLeft) {
|
|
109
|
+
// key = 'right';
|
|
110
|
+
// } else if (orientation === UIDeviceOrientation.LandscapeRight) {
|
|
111
|
+
// key = 'left';
|
|
112
|
+
// } else if (orientation === UIDeviceOrientation.PortraitUpsideDown) {
|
|
113
|
+
// key = 'top';
|
|
114
|
+
// }
|
|
115
|
+
const delta = fullscreenPosition[key] - safeAreaPosition[key];
|
|
116
|
+
effectiveHeight -= delta;
|
|
117
|
+
adjustedPosition[key] += delta; // extend frame into bottom safe area so background covers home indicator
|
|
118
|
+
}
|
|
119
|
+
if (orientation === 4 /* UIDeviceOrientation.LandscapeRight */ || orientation === 3 /* UIDeviceOrientation.LandscapeLeft */) {
|
|
120
|
+
const key = 'left';
|
|
121
|
+
const oppositeKey = 'right';
|
|
122
|
+
const delta = fullscreenPosition[key] - safeAreaPosition[key];
|
|
123
|
+
adjustedPosition[oppositeKey] += Utils.layout.toDevicePixels(delta);
|
|
124
|
+
// adjustedPosition[key] += (delta);
|
|
125
|
+
// adjustedPosition[oppositeKey] += Utils.layout.toDevicePixels(delta);
|
|
126
|
+
// adjustedPosition[key] += Utils.layout.toDevicePixels(delta);
|
|
127
|
+
}
|
|
128
|
+
if (owner.nativeViewProtected) {
|
|
129
|
+
owner.nativeViewProtected.frame = CGRectMake(Utils.layout.toDeviceIndependentPixels(adjustedPosition.left), Utils.layout.toDeviceIndependentPixels(adjustedPosition.top), Utils.layout.toDeviceIndependentPixels(adjustedPosition.right), Utils.layout.toDeviceIndependentPixels(adjustedPosition.bottom));
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
controller.preferredContentSize = CGSizeMake(Utils.layout.toDeviceIndependentPixels(effectiveWidth), Utils.layout.toDeviceIndependentPixels(effectiveHeight));
|
|
133
|
+
if (owner.parent) {
|
|
134
|
+
owner.parent._layoutParent();
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
function getAvailableSpaceFromParent(view, frame) {
|
|
138
|
+
if (!view) {
|
|
139
|
+
return null;
|
|
140
|
+
}
|
|
141
|
+
let scrollView = null;
|
|
142
|
+
let viewControllerView = null;
|
|
143
|
+
if (view.viewController) {
|
|
144
|
+
viewControllerView = view.viewController.view;
|
|
145
|
+
}
|
|
146
|
+
else {
|
|
147
|
+
let parent = view.parent;
|
|
148
|
+
while (parent && !parent.viewController && !(parent.nativeViewProtected instanceof UIScrollView)) {
|
|
149
|
+
parent = parent.parent;
|
|
150
|
+
}
|
|
151
|
+
if (parent) {
|
|
152
|
+
if (parent.nativeViewProtected instanceof UIScrollView) {
|
|
153
|
+
scrollView = parent.nativeViewProtected;
|
|
154
|
+
}
|
|
155
|
+
else if (parent.viewController) {
|
|
156
|
+
viewControllerView = parent.viewController.view;
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
let fullscreen = null;
|
|
161
|
+
let safeArea = null;
|
|
162
|
+
if (viewControllerView) {
|
|
163
|
+
safeArea = viewControllerView.safeAreaLayoutGuide.layoutFrame;
|
|
164
|
+
fullscreen = viewControllerView.frame;
|
|
165
|
+
}
|
|
166
|
+
else if (scrollView) {
|
|
167
|
+
const insets = scrollView.safeAreaInsets;
|
|
168
|
+
safeArea = CGRectMake(insets.left, insets.top, scrollView.contentSize.width - insets.left - insets.right, scrollView.contentSize.height - insets.top - insets.bottom);
|
|
169
|
+
fullscreen = CGRectMake(0, 0, scrollView.contentSize.width, scrollView.contentSize.height);
|
|
170
|
+
}
|
|
171
|
+
// const locationInWindow = view.getLocationInWindow();
|
|
172
|
+
// let inWindowLeft = locationInWindow.x;
|
|
173
|
+
// let inWindowTop = locationInWindow.y;
|
|
174
|
+
// if (scrollView) {
|
|
175
|
+
// inWindowLeft += scrollView.contentOffset.x;
|
|
176
|
+
// inWindowTop += scrollView.contentOffset.y;
|
|
177
|
+
// }
|
|
178
|
+
// const inWindow = CGRectMake(inWindowLeft, inWindowTop, frame.size.width, frame.size.height);
|
|
179
|
+
return { safeArea, fullscreen };
|
|
180
|
+
}
|
|
181
|
+
var MDLayoutViewController = /** @class */ (function (_super) {
|
|
182
|
+
__extends(MDLayoutViewController, _super);
|
|
183
|
+
function MDLayoutViewController() {
|
|
184
|
+
return _super !== null && _super.apply(this, arguments) || this;
|
|
185
|
+
}
|
|
186
|
+
MDLayoutViewController.initWithOwner = function (owner) {
|
|
187
|
+
var delegate = MDLayoutViewController.new();
|
|
188
|
+
delegate.owner = new WeakRef(owner);
|
|
189
|
+
return delegate;
|
|
190
|
+
};
|
|
191
|
+
MDLayoutViewController.prototype.viewDidLoad = function () {
|
|
192
|
+
var _a;
|
|
193
|
+
_super.prototype.viewDidLoad.call(this);
|
|
194
|
+
var owner = (_a = this.owner) === null || _a === void 0 ? void 0 : _a.get();
|
|
195
|
+
if (!owner) {
|
|
196
|
+
return;
|
|
197
|
+
}
|
|
198
|
+
if (!owner.isLoaded) {
|
|
199
|
+
owner.callLoaded();
|
|
200
|
+
}
|
|
201
|
+
// Unify translucent and opaque bars layout
|
|
202
|
+
this.edgesForExtendedLayout = UIRectEdge.All;
|
|
203
|
+
this.extendedLayoutIncludesOpaqueBars = true;
|
|
204
|
+
};
|
|
205
|
+
MDLayoutViewController.prototype.viewWillLayoutSubviews = function () {
|
|
206
|
+
var _a;
|
|
207
|
+
_super.prototype.viewWillLayoutSubviews.call(this);
|
|
208
|
+
var owner = (_a = this.owner) === null || _a === void 0 ? void 0 : _a.get();
|
|
209
|
+
if (owner) {
|
|
210
|
+
owner.iosOverflowSafeArea = true;
|
|
211
|
+
IOSHelper.updateConstraints(this, owner);
|
|
212
|
+
}
|
|
213
|
+
};
|
|
214
|
+
MDLayoutViewController.prototype.viewDidLayoutSubviews = function () {
|
|
215
|
+
var _a, _b;
|
|
216
|
+
_super.prototype.viewDidLayoutSubviews.call(this);
|
|
217
|
+
var owner = (_a = this.owner) === null || _a === void 0 ? void 0 : _a.get();
|
|
218
|
+
if (owner) {
|
|
219
|
+
layoutView(this, owner);
|
|
220
|
+
(_b = this.onLayoutCallback) === null || _b === void 0 ? void 0 : _b.call(this);
|
|
221
|
+
}
|
|
222
|
+
// safeAreaInsetsDidChange inflates contentInset.bottom on this layout pass, floating
|
|
223
|
+
// the sheet above the home indicator; reset it so the sheet stays at preferredSheetHeight
|
|
224
|
+
var trackingScrollView = this._trackingScrollView;
|
|
225
|
+
if (trackingScrollView) {
|
|
226
|
+
var inset = trackingScrollView.contentInset;
|
|
227
|
+
if (inset.bottom > 0) {
|
|
228
|
+
//@ts-expect-error missing typing
|
|
229
|
+
trackingScrollView.contentInset = UIEdgeInsetsMake(inset.top, inset.left, 0, inset.right);
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
};
|
|
233
|
+
MDLayoutViewController.prototype.viewWillAppear = function (animated) {
|
|
234
|
+
var _a;
|
|
235
|
+
_super.prototype.viewWillAppear.call(this, animated);
|
|
236
|
+
var owner = (_a = this.owner) === null || _a === void 0 ? void 0 : _a.get();
|
|
237
|
+
if (!owner) {
|
|
238
|
+
return;
|
|
239
|
+
}
|
|
240
|
+
IOSHelper.updateAutoAdjustScrollInsets(this, owner);
|
|
241
|
+
// if (!owner.parent) {
|
|
242
|
+
// owner.callLoaded();
|
|
243
|
+
// }
|
|
244
|
+
};
|
|
245
|
+
MDLayoutViewController.prototype.viewDidDisappear = function (animated) {
|
|
246
|
+
_super.prototype.viewDidDisappear.call(this, animated);
|
|
247
|
+
// let s not call callUnloaded here in case
|
|
248
|
+
// another modal / sheet is shown on top
|
|
249
|
+
// will be called on dismiss
|
|
250
|
+
};
|
|
251
|
+
// Mind implementation for other controllers
|
|
252
|
+
MDLayoutViewController.prototype.traitCollectionDidChange = function (previousTraitCollection) {
|
|
253
|
+
var _a;
|
|
254
|
+
_super.prototype.traitCollectionDidChange.call(this, previousTraitCollection);
|
|
255
|
+
if (majorVersion >= 13) {
|
|
256
|
+
var owner = (_a = this.owner) === null || _a === void 0 ? void 0 : _a.get();
|
|
257
|
+
if (owner &&
|
|
258
|
+
this.traitCollection.hasDifferentColorAppearanceComparedToTraitCollection &&
|
|
259
|
+
this.traitCollection.hasDifferentColorAppearanceComparedToTraitCollection(previousTraitCollection)) {
|
|
260
|
+
owner.notify({ eventName: 'traitCollectionColorAppearanceChanged', object: owner });
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
};
|
|
264
|
+
return MDLayoutViewController;
|
|
265
|
+
}(UIViewController));
|
|
266
|
+
export { MDLayoutViewController };
|
|
267
|
+
//# sourceMappingURL=ios-layout.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ios-layout.js","sourceRoot":"","sources":["../../src/ui-bottomsheet/ios-layout.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,SAAS,EAAE,MAAM,EAAE,KAAK,EAAE,KAAK,EAAE,IAAI,EAAE,MAAM,oBAAoB,CAAC;AAExF,MAAM,YAAY,GAAG,KAAK,CAAC,GAAG,CAAC,YAAY,CAAC;AAE5C;;;GAGG;AACH,MAAM,UAAU,uBAAuB,CAAC,MAAY,EAAE,WAAiB,WAAW,CAAC,WAAW,EAAE;IAC5F,IAAI,QAAQ,CAAC,MAAM,EAAE,CAAC;QAClB,QAAQ,GAAG,QAAQ,CAAC,MAAa,CAAC;IACtC,CAAC;IACD,MAAM,WAAW,GAAG,MAAM,CAAC,KAAK,IAAI,MAAM,CAAC;IAC3C,IAAI,gBAAgB,GAAG,WAAW,CAAC,cAAc,CAAC;IAClD,IAAI,CAAC,gBAAgB,CAAC,uBAAuB,IAAI,QAAQ,CAAC,cAAc,CAAC,uBAAuB,EAAE,CAAC;QAC/F,gBAAgB,GAAG,QAAQ,CAAC,cAAc,CAAC,uBAAuB,CAAC;IACvE,CAAC;IACD,OAAO,gBAAgB,CAAC,uBAAuB,EAAE,CAAC;QAC9C,OACI,gBAAgB,CAAC,uBAAuB,YAAY,iBAAiB;YACrE,CAAC,gBAAgB,CAAC,uBAAuB,CAAC,mBAAmB,CAAC,IAAI,gBAAgB,CAAC,uBAAuB,CAAC,uBAAuB,CAAC,EACrI,CAAC;YACC,gBAAgB,GAAG,gBAAgB,CAAC,uBAAuB,CAAC;QAChE,CAAC;QACD,IAAI,gBAAgB,CAAC,uBAAuB,YAAY,iBAAiB,IAAI,gBAAgB,CAAC,uBAAuB,CAAC,mBAAmB,CAAC,EAAE,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,CAAC;AACpC,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,50 @@
|
|
|
1
1
|
{
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
2
|
+
"name": "@nativescript-community/ui-bottomsheet",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "BottomSheet: showBottomSheet()/closeBottomSheet() on every View. Material on Android, native UISheetPresentationController on iOS.",
|
|
5
|
+
"main": "./index",
|
|
6
|
+
"sideEffects": false,
|
|
7
|
+
"typings": "./index.d.ts",
|
|
8
|
+
"scripts": {
|
|
9
|
+
"tsc": "cpy '**/*.d.ts' '../../packages/ui-bottomsheet' --parents --cwd=../../src/ui-bottomsheet && tsc --build",
|
|
10
|
+
"readme": "readme generate -c ../../tools/readme/blueprint.json",
|
|
11
|
+
"build": "npm run tsc && npm run readme",
|
|
12
|
+
"build.watch": "npm run tsc -- -w",
|
|
13
|
+
"build.all": "npm run build",
|
|
14
|
+
"clean": "bin/rimraf ./*.d.ts ./*.js ./*.js.map ./*.tsbuildinfo ./*.mjs ./*.mjs.map ./angular ./svelte ./vue* ./react"
|
|
15
|
+
},
|
|
16
|
+
"nativescript": {
|
|
17
|
+
"platforms": {
|
|
18
|
+
"android": "6.2.0",
|
|
19
|
+
"ios": "6.2.0"
|
|
20
|
+
}
|
|
21
|
+
},
|
|
22
|
+
"keywords": [
|
|
23
|
+
"NativeScript",
|
|
24
|
+
"JavaScript",
|
|
25
|
+
"Android",
|
|
26
|
+
"iOS"
|
|
27
|
+
],
|
|
28
|
+
"author": {
|
|
29
|
+
"name": "Martin Guillon",
|
|
30
|
+
"email": "martin@akylas.fr"
|
|
31
|
+
},
|
|
32
|
+
"bugs": {
|
|
33
|
+
"url": "https://github.com/nativescript-community/ui-native-components/issues"
|
|
34
|
+
},
|
|
35
|
+
"license": "Apache-2.0",
|
|
36
|
+
"publishConfig": {
|
|
37
|
+
"access": "public"
|
|
38
|
+
},
|
|
39
|
+
"homepage": "https://github.com/nativescript-community/ui-native-components/tree/master/packages/ui-bottomsheet#readme",
|
|
40
|
+
"repository": {
|
|
41
|
+
"type": "git",
|
|
42
|
+
"url": "https://github.com/nativescript-community/ui-native-components.git",
|
|
43
|
+
"directory": "packages/ui-bottomsheet"
|
|
44
|
+
},
|
|
45
|
+
"readmeFilename": "README.md",
|
|
46
|
+
"dependencies": {
|
|
47
|
+
"@nativescript-community/ui-core": "^1.0.0"
|
|
48
|
+
},
|
|
49
|
+
"gitHead": "237dd97d2b9e0f62ea9d9810169bb800dd531f7b"
|
|
50
|
+
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
package com.nativescript.ui.bottomsheet;
|
|
2
|
+
|
|
3
|
+
import android.content.Context;
|
|
4
|
+
import android.view.ViewGroup;
|
|
5
|
+
import android.view.View;
|
|
6
|
+
|
|
7
|
+
public class BottomSheetDialog extends com.google.android.material.bottomsheet.BottomSheetDialog {
|
|
8
|
+
public interface BottomSheetDialogListener {
|
|
9
|
+
boolean onBackPressed(BottomSheetDialog dialog);
|
|
10
|
+
|
|
11
|
+
void onDetachedFromWindow(BottomSheetDialog dialog);
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
BottomSheetDialogListener listener;
|
|
15
|
+
|
|
16
|
+
public BottomSheetDialog(Context context, int themeResId) {
|
|
17
|
+
super(context, themeResId);
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
public void setListener(BottomSheetDialogListener listener) {
|
|
21
|
+
this.listener = listener;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
@Override
|
|
25
|
+
public void onBackPressed() {
|
|
26
|
+
if (listener == null || !listener.onBackPressed(this)) {
|
|
27
|
+
super.onBackPressed();
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
public void onDetachedFromWindow() {
|
|
32
|
+
super.onDetachedFromWindow();
|
|
33
|
+
if (listener != null) {
|
|
34
|
+
listener.onDetachedFromWindow(this);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
}
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
package com.nativescript.ui.bottomsheet;
|
|
2
|
+
|
|
3
|
+
import android.content.Context;
|
|
4
|
+
import android.view.ViewGroup;
|
|
5
|
+
import android.view.View;
|
|
6
|
+
|
|
7
|
+
public class BottomSheetDialogFragment extends com.google.android.material.bottomsheet.BottomSheetDialogFragment {
|
|
8
|
+
public interface BottomSheetDialogFragmentListener {
|
|
9
|
+
android.app.Dialog onCreateDialog(BottomSheetDialogFragment fragment, android.os.Bundle savedInstanceState);
|
|
10
|
+
|
|
11
|
+
android.view.View onCreateView(BottomSheetDialogFragment fragment, android.view.LayoutInflater inflater, android.view.ViewGroup container,
|
|
12
|
+
android.os.Bundle savedInstanceState);
|
|
13
|
+
|
|
14
|
+
void onStart(BottomSheetDialogFragment fragment);
|
|
15
|
+
|
|
16
|
+
void onDismiss(BottomSheetDialogFragment fragment, android.content.DialogInterface dialog);
|
|
17
|
+
|
|
18
|
+
void onDestroy(BottomSheetDialogFragment fragment);
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
BottomSheetDialogFragmentListener listener;
|
|
22
|
+
|
|
23
|
+
public BottomSheetDialogFragment() {
|
|
24
|
+
super();
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
public void setListener(BottomSheetDialogFragmentListener listener) {
|
|
28
|
+
this.listener = listener;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
@Override
|
|
32
|
+
public android.app.Dialog onCreateDialog(android.os.Bundle savedInstanceState) {
|
|
33
|
+
if (listener != null) {
|
|
34
|
+
return listener.onCreateDialog(this, savedInstanceState);
|
|
35
|
+
}
|
|
36
|
+
return super.onCreateDialog(savedInstanceState);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
@Override
|
|
40
|
+
public android.view.View onCreateView(android.view.LayoutInflater inflater, android.view.ViewGroup container,
|
|
41
|
+
android.os.Bundle savedInstanceState) {
|
|
42
|
+
if (listener != null) {
|
|
43
|
+
return listener.onCreateView(this, inflater, container, savedInstanceState);
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
return super.onCreateView(inflater, container, savedInstanceState);
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
@Override
|
|
50
|
+
public void onStart() {
|
|
51
|
+
super.onStart();
|
|
52
|
+
if (listener != null) {
|
|
53
|
+
listener.onStart(this);
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
@Override
|
|
58
|
+
public void onDismiss(android.content.DialogInterface dialog) {
|
|
59
|
+
super.onDismiss(dialog);
|
|
60
|
+
if (listener != null) {
|
|
61
|
+
listener.onDismiss(this, dialog);
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
@Override
|
|
66
|
+
public void onDestroy() {
|
|
67
|
+
super.onDestroy();
|
|
68
|
+
if (listener != null) {
|
|
69
|
+
listener.onDestroy(this);
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
{
|
|
2
|
+
"uses": [
|
|
3
|
+
"android.app:Dialog",
|
|
4
|
+
"android.content:Context",
|
|
5
|
+
"android.content:DialogInterface",
|
|
6
|
+
"android.os:Bundle",
|
|
7
|
+
"android.view:Gravity",
|
|
8
|
+
"android.view:LayoutInflater",
|
|
9
|
+
"android.view:MotionEvent",
|
|
10
|
+
"android.view:View",
|
|
11
|
+
"android.view:View.OnClickListener",
|
|
12
|
+
"android.view:View.OnTouchListener",
|
|
13
|
+
"android.view:ViewGroup",
|
|
14
|
+
"android.view:ViewGroup.LayoutParams",
|
|
15
|
+
"android.view:ViewGroup.MarginLayoutParams",
|
|
16
|
+
"android.view:Window",
|
|
17
|
+
"android.view:WindowManager.LayoutParams",
|
|
18
|
+
"android.webkit:WebView",
|
|
19
|
+
"android.widget:AbsListView",
|
|
20
|
+
"android.widget:FrameLayout.LayoutParams",
|
|
21
|
+
"android.widget:ScrollView",
|
|
22
|
+
"androidx.appcompat.app:AppCompatActivity",
|
|
23
|
+
"androidx.core.view:ViewCompat",
|
|
24
|
+
"com.google.android.material.bottomsheet:BottomSheetBehavior",
|
|
25
|
+
"com.google.android.material.bottomsheet:BottomSheetBehavior.BottomSheetCallback",
|
|
26
|
+
"com.google.android.material.bottomsheet:BottomSheetDialogFragment",
|
|
27
|
+
"com.google.android.material.bottomsheet:BottomSheetDragHandleView",
|
|
28
|
+
"com.google.android.material.shape:MaterialShapeDrawable",
|
|
29
|
+
"com.nativescript.ui.bottomsheet:BottomSheetDialog",
|
|
30
|
+
"com.nativescript.ui.bottomsheet:BottomSheetDialog.BottomSheetDialogListener",
|
|
31
|
+
"com.nativescript.ui.bottomsheet:BottomSheetDialogFragment",
|
|
32
|
+
"com.nativescript.ui.bottomsheet:BottomSheetDialogFragment.BottomSheetDialogFragmentListener"
|
|
33
|
+
]
|
|
34
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { BottomSheetOptions } from '../index';
|
|
2
|
+
import { View } from '@nativescript/core';
|
|
3
|
+
import { NativeViewElementNode } from '@nativescript-community/svelte-native/dom';
|
|
4
|
+
import { PageSpec } from '@nativescript-community/svelte-native/dom/navigation';
|
|
5
|
+
declare module '@nativescript/core/ui/core/view' {
|
|
6
|
+
interface View {
|
|
7
|
+
closeBottomSheet(...args: any): void;
|
|
8
|
+
showBottomSheet(options: BottomSheetOptions): View;
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
export interface SvelteShowBottomSheetOptions<U> extends Omit<BottomSheetOptions, 'view'> {
|
|
12
|
+
view: PageSpec<U>;
|
|
13
|
+
parent?: NativeViewElementNode<View> | View;
|
|
14
|
+
props?: U;
|
|
15
|
+
}
|
|
16
|
+
interface ComponentInstanceInfo {
|
|
17
|
+
element: NativeViewElementNode<View>;
|
|
18
|
+
viewInstance: SvelteComponent;
|
|
19
|
+
}
|
|
20
|
+
export declare function resolveComponentElement<T>(viewSpec: typeof SvelteComponent<T>, props?: any): ComponentInstanceInfo;
|
|
21
|
+
export declare function showBottomSheet<T = any, U = any>(modalOptions: SvelteShowBottomSheetOptions<U>): Promise<T>;
|
|
22
|
+
export declare function closeBottomSheet(result?: any): void;
|
|
23
|
+
export declare function isBottomSheetOpened(): boolean;
|
|
24
|
+
export {};
|
package/svelte/index.js
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { Frame, View } from '@nativescript/core';
|
|
2
|
+
import { createElement } from '@nativescript-community/svelte-native/dom';
|
|
3
|
+
const modalStack = [];
|
|
4
|
+
export function resolveComponentElement(viewSpec, props) {
|
|
5
|
+
const dummy = createElement('fragment', window.document);
|
|
6
|
+
const viewInstance = new viewSpec({ target: dummy, props });
|
|
7
|
+
const element = dummy.firstElement();
|
|
8
|
+
return { element, viewInstance };
|
|
9
|
+
}
|
|
10
|
+
export function showBottomSheet(modalOptions) {
|
|
11
|
+
const { view, parent, props = {}, ...options } = modalOptions;
|
|
12
|
+
// Get this before any potential new frames are created by component below
|
|
13
|
+
const modalLauncher = (parent && (parent instanceof View ? parent : parent.nativeView)) || Frame.topmost().currentPage;
|
|
14
|
+
const componentInstanceInfo = resolveComponentElement(view, props);
|
|
15
|
+
let modalView = componentInstanceInfo.element.nativeView;
|
|
16
|
+
return new Promise(async (resolve, reject) => {
|
|
17
|
+
let resolved = false;
|
|
18
|
+
const closeCallback = (result) => {
|
|
19
|
+
if (resolved)
|
|
20
|
+
return;
|
|
21
|
+
resolved = true;
|
|
22
|
+
if (options.closeCallback) {
|
|
23
|
+
options.closeCallback(result, componentInstanceInfo.viewInstance);
|
|
24
|
+
}
|
|
25
|
+
modalStack.pop();
|
|
26
|
+
resolve(result);
|
|
27
|
+
modalView._tearDownUI();
|
|
28
|
+
componentInstanceInfo.viewInstance.$destroy(); // don't let an exception in destroy kill the promise callback
|
|
29
|
+
};
|
|
30
|
+
try {
|
|
31
|
+
modalLauncher.showBottomSheet({ view: modalView, ...options, context: {}, closeCallback });
|
|
32
|
+
modalStack.push(componentInstanceInfo);
|
|
33
|
+
}
|
|
34
|
+
catch (err) {
|
|
35
|
+
reject(err);
|
|
36
|
+
}
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
export function closeBottomSheet(result) {
|
|
40
|
+
const modalPageInstanceInfo = modalStack[modalStack.length - 1];
|
|
41
|
+
if (modalPageInstanceInfo) {
|
|
42
|
+
modalPageInstanceInfo.element.nativeView.closeBottomSheet(result);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
export function isBottomSheetOpened() {
|
|
46
|
+
return modalStack.length > 0;
|
|
47
|
+
}
|
|
48
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/ui-bottomsheet/svelte/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,EAAE,IAAI,EAAE,MAAM,oBAAoB,CAAC;AACjD,OAAO,EAAyB,aAAa,EAAE,MAAM,2CAA2C,CAAC;AAoBjG,MAAM,UAAU,GAA4B,EAAE,CAAC;AAE/C,MAAM,UAAU,uBAAuB,CAAI,QAAmC,EAAE,KAAW;IACvF,MAAM,KAAK,GAAG,aAAa,CAAC,UAAU,EAAE,MAAM,CAAC,QAAe,CAAC,CAAC;IAChE,MAAM,YAAY,GAAG,IAAI,QAAQ,CAAC,EAAE,MAAM,EAAE,KAAK,EAAE,KAAK,EAAE,CAAC,CAAC;IAC5D,MAAM,OAAO,GAAG,KAAK,CAAC,YAAY,EAAiC,CAAC;IACpE,OAAO,EAAE,OAAO,EAAE,YAAY,EAAE,CAAC;AACrC,CAAC;AAED,MAAM,UAAU,eAAe,CAAmB,YAA6C;IAC3F,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,KAAK,GAAG,EAAE,EAAE,GAAG,OAAO,EAAE,GAAG,YAAY,CAAC;IAC9D,0EAA0E;IAC1E,MAAM,aAAa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AU,CAAC,UAAU,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC;IAChE,IAAI,qBAAqB,EAAE,CAAC;QACvB,qBAAqB,CAAC,OAAO,CAAC,UAAkB,CAAC,gBAAgB,CAAC,MAAM,CAAC,CAAC;IAC/E,CAAC;AACL,CAAC;AACD,MAAM,UAAU,mBAAmB;IAC/B,OAAO,UAAU,CAAC,MAAM,GAAG,CAAC,CAAC;AACjC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"root":["../../src/ui-bottomsheet/index-common.ts","../../src/ui-bottomsheet/index.android.ts","../../src/ui-bottomsheet/index.d.ts","../../src/ui-bottomsheet/index.ios.ts","../../src/ui-bottomsheet/ios-layout.ts","../../src/ui-bottomsheet/svelte/index.ts","../../references.d.ts","../../tools/references.d.ts","../../src/references.d.ts"],"version":"5.8.3"}
|