svelte-native icon indicating copy to clipboard operation
svelte-native copied to clipboard

Svelte context API does not work with NativeScript navigators

Open bretep opened this issue 2 years ago • 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 avatar Oct 31 '22 19:10 bretep

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

bretep avatar Oct 31 '22 19:10 bretep

@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

vallemar avatar Apr 03 '23 13:04 vallemar