Skip to content

Commit a8504de

Browse files
committed
fix: crash fix while changing app language
1 parent a2a27f8 commit a8504de

3 files changed

Lines changed: 50 additions & 43 deletions

File tree

app/app.common.scss

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@ htmllabel {
107107

108108

109109
page {
110+
navigation-bar-color: var(--colorBackground);
110111
status-bar-color: transparent;
111112
status-bar-style: light;
112113
background-color: var(--colorBackground);

app/main.ts

Lines changed: 41 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,13 @@ import { startSentry } from '@shared/utils/sentry';
1818
import { showError } from '@shared/utils/showError';
1919
import { navigate } from '@shared/utils/svelte/ui';
2020
import { FrameElement, PageElement, createElement, registerElement, registerNativeViewElement } from 'svelte-native/dom';
21-
import PacksList from '~/components/App.svelte';
21+
import App from '~/components/App.svelte';
2222
import { getBGServiceInstance } from '~/services/BgService';
2323
import { setDocumentsService } from './models/Pack';
2424
import { networkService } from './services/api';
2525
import { createSharedDocumentsService, documentsService } from './services/documents';
2626
import { importService } from './services/importservice';
27+
import { svelteNativeNoFrame } from 'svelte-native';
2728
// import './app.scss';
2829
declare module '@nativescript/core/application/application-common' {
2930
interface ApplicationCommon {
@@ -161,45 +162,46 @@ try {
161162
}
162163
});
163164
sharedInit();
165+
svelteNativeNoFrame(App, {});
164166

165-
let rootFrame;
166-
let pageInstance;
167-
// we use custom start cause we want gesturerootview as parent of it all to add snacK message view
168-
new Promise((resolve, reject) => {
169-
//wait for launch
170-
Application.on(Application.launchEvent, () => {
171-
DEV_LOG && console.log('launch', !!pageInstance);
172-
resolve(pageInstance);
173-
});
174-
Application.on(Application.exitEvent, () => {
175-
DEV_LOG && console.log('exit', !!pageInstance);
176-
if (pageInstance) {
177-
pageInstance.$destroy();
178-
pageInstance = null;
179-
}
180-
});
181-
try {
182-
Application.run({
183-
create: () => {
184-
const rootGridLayout = createElement('gesturerootview', window.document as any);
185-
const rootFrame = createElement('frame', rootGridLayout.ownerDocument);
186-
rootFrame.setAttribute('id', 'app-root-frame');
187-
//very important here to use svelte-native navigate
188-
// the throttle one wont return the pageInstance
189-
pageInstance = navigate({
190-
page: PacksList,
191-
props: {},
192-
frame: rootFrame as any
193-
});
194-
DEV_LOG && console.log('Application.run', !!pageInstance);
195-
rootGridLayout.appendChild(rootFrame);
196-
return rootGridLayout['nativeView'];
197-
}
198-
});
199-
} catch (e) {
200-
reject(e);
201-
}
202-
});
167+
// let rootFrame;
168+
// let pageInstance;
169+
// // we use custom start cause we want gesturerootview as parent of it all to add snacK message view
170+
// new Promise((resolve, reject) => {
171+
// //wait for launch
172+
// Application.on(Application.launchEvent, () => {
173+
// DEV_LOG && console.log('launch', !!pageInstance);
174+
// resolve(pageInstance);
175+
// });
176+
// Application.on(Application.exitEvent, () => {
177+
// DEV_LOG && console.log('exit', !!pageInstance);
178+
// if (pageInstance) {
179+
// pageInstance.$destroy();
180+
// pageInstance = null;
181+
// }
182+
// });
183+
// try {
184+
// Application.run({
185+
// create: () => {
186+
// const rootGridLayout = createElement('gesturerootview', window.document as any);
187+
// const rootFrame = createElement('frame', rootGridLayout.ownerDocument);
188+
// rootFrame.setAttribute('id', 'app-root-frame');
189+
// //very important here to use svelte-native navigate
190+
// // the throttle one wont return the pageInstance
191+
// pageInstance = navigate({
192+
// page: App,
193+
// props: {},
194+
// frame: rootFrame as any
195+
// });
196+
// DEV_LOG && console.log('Application.run', !!pageInstance);
197+
// rootGridLayout.appendChild(rootFrame);
198+
// return rootGridLayout['nativeView'];
199+
// }
200+
// });
201+
// } catch (e) {
202+
// reject(e);
203+
// }
204+
// });
203205
} catch (error) {
204206
console.error(error, error.stack);
205207
}

app/utils/ui/index.common.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -246,11 +246,15 @@ export interface ShowSnackMessageOptions {
246246
}
247247
let snackMessage: ComponentInstanceInfo<GridLayout, BottomSnack__SvelteComponent_>;
248248
let snackMessageVisible = false;
249+
250+
function getSnackMessageParent(): GridLayout {
251+
return Application.getRootView().getViewById('inner-frame-holder');
252+
}
249253
function getSnackMessage(props?) {
250254
if (!snackMessage) {
251255
try {
252256
snackMessage = resolveComponentElement(BottomSnack, props || {}) as ComponentInstanceInfo<GridLayout, BottomSnack__SvelteComponent_>;
253-
(Application.getRootView() as GridLayout).addChild(snackMessage.element.nativeView);
257+
getSnackMessageParent().addChild(snackMessage.element.nativeView);
254258
} catch (error) {
255259
console.error(error, error.stack);
256260
}
@@ -303,7 +307,7 @@ export async function hideSnackMessage() {
303307
if (snackMessage) {
304308
snackMessageVisible = false;
305309
await animateSnackMessage(100, false);
306-
(Application.getRootView() as GridLayout).removeChild(snackMessage.element.nativeView);
310+
getSnackMessageParent().removeChild(snackMessage.element.nativeView);
307311
snackMessage.element.nativeElement._tearDownUI();
308312
snackMessage.viewInstance.$destroy();
309313
snackMessage = null;
@@ -317,8 +321,8 @@ function getAudioPlayer(props?: BarPlayerOptions) {
317321
if (!barPlayer) {
318322
try {
319323
barPlayer = resolveComponentElement(BarAudioPlayer, props || {}) as ComponentInstanceInfo<GridLayout, BarAudioPlayer__SvelteComponent_>;
320-
// eslint-disable-next-line @typescript-eslint/no-unnecessary-type-assertion
321-
(Application.getRootView().getViewById('inner-frame-holder') as GridLayout).addChild(barPlayer.element.nativeView);
324+
325+
getSnackMessageParent().addChild(barPlayer.element.nativeView);
322326
} catch (error) {
323327
console.error(error, error.stack);
324328
}

0 commit comments

Comments
 (0)