android / nowinandroid

A fully functional Android app built entirely with Kotlin and Jetpack Compose
Apache License 2.0
15.92k stars 2.81k forks source link

refactor: On ui layer analytics injected by entrypoint #1472

Open rhkrwngud445 opened 1 month ago

rhkrwngud445 commented 1 month ago

Issue: #1471

Suggest changing the UI layer injection method of Analytics Instance in Analytics Module.

Instead of using CompositionLocal, how about using Hilt's EntryPoint?

It has these advantages.

  1. It has the advantage of reducing MainActivity injection code.
  2. Management outside HiltScope can be reduced.
  3. Analytics can eliminate compose dependency.

Additionally, in analytics/AnalyticsModule, how about creating an instance as a singleton?

yongsuk44 commented 1 month ago

This is just a chat, but if a Composable that calls analyticsInstance() leaves the Composition and later AnalyticsHelper is needed again, it seems necessary to fetch the object from the dependency graph again. In the existing implementation, it is managed by the Activity Lifecycle, so I think there wouldn't be such unnecessary overhead. What do you think?

Additionally, according to the comments in the existing code, NoOpAnalyticsHelper() is used to run the Preview. Do you think the modified code can replace it?

rhkrwngud445 commented 1 month ago

@yongsuk44 Thanks for your feedback

Additionally, according to the comments in the existing code, NoOpAnalyticsHelper() is used to run the Preview. Do you think the modified code can replace it?

I think it is changed by the lambda code so that preview will be OK

example commit

This is just a chat, but if a Composable that calls analyticsInstance() leaves the Composition and later AnalyticsHelper is needed again, it seems necessary to fetch the object from the dependency graph again. In the existing implementation, it is managed by the Activity Lifecycle, so I think there wouldn't be such unnecessary overhead. What do you think?

I also agree that cost existed. It was confirmed that there was a difference of more than 5000 NanoTime. I think that it seems to be a trade-off area with the advantages I suggested.

yongsuk44 commented 1 month ago
  1. I think it would be simpler to write TrackScreenViewEvent in the InterestsRoute rather than hoisting. I'm curious if it's possible to replace the previews of components like userNewsResourceCardItems and newsFeed.

  2. It seems to me that comparing how much the frame changes through ScrollForYouFeedBenchmark would make things clearer. What do you think?

rhkrwngud445 commented 1 month ago

@yongsuk44 I think improvements can be made with a nested callback structure, but I don't think it's a good structure.

I suggested CompositionLocal because I was wondering why, and I found the answer. Your suggestions and questions were helpful. Thank you.