halfnelson/svelte-native

Svelte context API does not work with NativeScript navigators

bretep opened this issue · 2 comments

Problem

Wrapping your app in a svelte context does not work when navigating to a new page:
Example: https://github.com/bretep/context-example

Why

Svelte uses the current component to set the context. All child components have access to the context of the parent components.
https://github.com/sveltejs/svelte/blob/master/src/runtime/internal/lifecycle.ts

When navigating to a new page using NativeScript navigators, the new page begins a new component tree and does not have a parent.

Solution

Other NativeScript frameworks have implemented their own navigation vs. using the NativeScript navigators. Likely because of functionality like parent-child relationships of the framework.
https://react-nativescript.netlify.app/docs/core-concepts/navigation#do-use-react-nativescript-navigation

@bretep I think that this is a problem similar in vue, In each navigation in vue apply the "plugins" that the default app use: https://github.com/nativescript-vue/nativescript-vue/blob/main/src/index.ts#L102

I think that you can do any similar here: https://github.com/halfnelson/svelte-native/blob/master/src/dom/navigation.ts#L64
or here https://github.com/halfnelson/svelte-native/blob/master/src/dom/navigation.ts#L49