Replies: 1 comment
-
|
For a bit more on this discussion, I had a chat with Joe for our recent Philippine Ruby Users Group Meetup which is viewable here: |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Greetings all,
I'm writing to bring your attention to a demo app I've created using hotwire native with Compose Multiplatform.
https://github.com/paglalayag/cmp-hotwire-demo/
My main motivation for doing this was to implement common code for database setup and local storage (between android and iOS).
the demo implements a HotwireWebview for my podcast (just a static jekyll site).
Then it implements a native audio player while hiding the html version.
One of the main design considerations I had was whether
MainActivityshould extendHotwireActivityor CMP'sComponentActivity. Ultimately I chose Hotwire.The demo app is just about feature complete for what I was hoping when I started. The main thing that is lacking (or that I haven't figured out how to do yet) is setting up a ViewModel bound to the HotwireActivity so that I can have shared state between the Hotwire Screen (plus any Composables on it), and the Native Screen.
In my case, if you run my app, there are 2 separate instances of
PodcastsViewModelcreated. One for each screen. The effect of this is that the player on each runs functions with its own state & independent of the other.This is implemented via
koinViewModelhttps://insert-koin.io/docs/reference/koin-android/viewmodel/According to this article https://developer.android.com/topic/libraries/architecture/viewmodel#implement-viewmodel
I am encouraged to create an
activity-bound ViewModel. which for koin & CMP is described herehttps://insert-koin.io/docs/reference/koin-android/viewmodel/#activity-shared-viewmodel
though I haven't gotten it working yet
Finally, I tried accessing the
ViewModelStoreOwnerviaviewModels()As per the screenshot below, this is avaiable in
ComponentActivitybut not yet inHotwireActivity.I also found this guidance, which ties the ViewModel to the nav graph.
https://insert-koin.io/docs/reference/koin-android/viewmodel/#navigation-graph-viewmodel
Perhaps this is the more natural place for state that has reach beyond a single screen.
Based on the above, I am contemplating 2 PRs:
by viewModels()or similar delegation based off the implementation inComponentActivitypossibly bound to the Hotwire Nav Graphbin/rails tailwindcss:installto automagically add the shared db code, etcWould love to hear any comments or impressions about this. Would PRs like this be welcome?
Many thanks. I'm diggin the library and approach so far!
Beta Was this translation helpful? Give feedback.
All reactions