halfnelson / svelte-native

Svelte controlling native components via Nativescript
MIT License
1.78k stars 77 forks source link

Svelte context API does not work with NativeScript navigators #316

Open bretep opened 1 year ago

bretep commented 1 year ago

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 commented 1 year ago

This issue was brought up in discord: https://ptb.discord.com/channels/603595811204366337/606457810217074708/1036623795106086922

vallemar commented 1 year ago

@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