Skip to content

Commit 05297da

Browse files
committed
fix: fixed tsc errors
1 parent 6f09342 commit 05297da

File tree

4 files changed

+23
-18
lines changed

4 files changed

+23
-18
lines changed

src/bottomsheet/bottomsheet-common.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ export const showingInBottomSheetEvent = 'showingInBottomSheet';
2828
export const closedSheetEvent = 'closedBottomSheet';
2929

3030
export interface BottomSheetOptions {
31-
view: string | ViewBase; // View instance to be shown in bottom sheet. Or the name of the module to load starting from the application root.
31+
view: string | View; // View instance to be shown in bottom sheet. Or the name of the module to load starting from the application root.
3232
context?: any; // Any context you want to pass to the view shown in bottom sheet. This same context will be available in the arguments of the shownInBottomSheet event handler.
3333
animated?: boolean; // An optional parameter specifying whether to show the sheet view with animation.
3434
dismissOnBackgroundTap?: boolean; // An optional parameter specifying whether to dismiss the sheet when clicking on background.
@@ -173,7 +173,7 @@ export abstract class ViewWithBottomSheetBase extends View {
173173
}
174174
}
175175

176-
public showBottomSheet(options: BottomSheetOptions): ViewBase {
176+
public showBottomSheet(options: BottomSheetOptions): View {
177177
if (arguments.length === 0) {
178178
throw new Error('showModal without parameters is deprecated. Please call showModal on a view instance instead.');
179179
} else {

src/bottomsheet/bottomsheet.ios.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ class MDCBottomSheetControllerDelegateImpl extends NSObject {
2424
}
2525
bottomSheetControllerDidChangeYOffsetYOffset(controller: MDCBottomSheetController, yOffset: number) {
2626
const owner = this._owner.get();
27-
if (owner && owner._onChangeStateBottomSheetCallback) {
27+
if (owner?._onChangeStateBottomSheetCallback) {
2828
const presentationController = controller.presentationController as MDCBottomSheetPresentationController;
2929
const heightScreen = Screen.mainScreen.heightDIPs;
3030
const heightCollapsedSheet = presentationController.preferredSheetHeight || controller.preferredContentSize.height;

src/bottomsheet/svelte/index.ts

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,19 @@
11
import { BottomSheetOptions } from '../bottomsheet';
2-
import { Frame, View, ViewBase } from '@nativescript/core';
2+
import { Frame, View } from '@nativescript/core';
33
import { NativeViewElementNode, createElement } from 'svelte-native/dom';
44
import { PageSpec } from 'svelte-native/dom/navigation';
55

6-
export interface ShowBottomSheetOptions extends Omit<BottomSheetOptions, 'view'> {
7-
view: PageSpec;
8-
parent: NativeViewElementNode<View> | View;
9-
props?: any;
6+
declare module '@nativescript/core/ui/core/view' {
7+
interface View {
8+
closeBottomSheet(...args: any): void;
9+
showBottomSheet(options: BottomSheetOptions): View;
10+
}
11+
}
12+
13+
export interface SvelteShowBottomSheetOptions<U> extends Omit<BottomSheetOptions, 'view'> {
14+
view: PageSpec<U>;
15+
parent?: NativeViewElementNode<View> | View;
16+
props?: U;
1017
}
1118
interface ComponentInstanceInfo {
1219
element: NativeViewElementNode<View>;
@@ -15,31 +22,29 @@ interface ComponentInstanceInfo {
1522

1623
const modalStack: ComponentInstanceInfo[] = [];
1724

18-
export function resolveComponentElement(viewSpec: PageSpec, props?: any): ComponentInstanceInfo {
19-
const dummy = createElement('fragment');
25+
export function resolveComponentElement<T>(viewSpec: typeof SvelteComponent<T>, props?: any): ComponentInstanceInfo {
26+
const dummy = createElement('fragment', window.document as any);
2027
const viewInstance = new viewSpec({ target: dummy, props });
2128
const element = dummy.firstElement() as NativeViewElementNode<View>;
2229
return { element, viewInstance };
2330
}
2431

25-
export function showBottomSheet<T>(modalOptions: ShowBottomSheetOptions): Promise<T> {
32+
export function showBottomSheet<T, U = any>(modalOptions: SvelteShowBottomSheetOptions<U>): Promise<T> {
2633
const { view, parent, props = {}, ...options } = modalOptions;
2734
// Get this before any potential new frames are created by component below
28-
const modalLauncher = (parent && (parent instanceof View ? parent : parent.nativeView)) || Frame.topmost().currentPage;
35+
const modalLauncher: View = (parent && (parent instanceof View ? parent : parent.nativeView)) || Frame.topmost().currentPage;
2936

3037
const componentInstanceInfo = resolveComponentElement(view, props);
31-
const modalView: ViewBase = componentInstanceInfo.element.nativeView;
38+
let modalView: View = componentInstanceInfo.element.nativeView;
3239

3340
return new Promise(async (resolve, reject) => {
3441
let resolved = false;
3542
const closeCallback = (result: T) => {
3643
if (resolved) return;
37-
const index = modalStack.indexOf(componentInstanceInfo);
38-
if (index !== -1) {
39-
modalStack.splice(index, 1);
40-
}
44+
modalStack.pop();
4145
resolved = true;
4246
resolve(result);
47+
modalView._tearDownUI();
4348
componentInstanceInfo.viewInstance.$destroy(); // don't let an exception in destroy kill the promise callback
4449
};
4550
try {

src/bottomsheet/vue3/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ const createNativeView = (component: any, props?: any): App => createApp(compone
8484

8585

8686
interface VueBottomSheetOptions extends Partial<BottomSheetOptions> {
87-
view?: string | ViewBase;
87+
view?: string | View;
8888
props?: any;
8989
on?: Record<string, (...args: any[]) => any>;
9090
}

0 commit comments

Comments
 (0)