Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add performAction function to ReEngagePrompt #2078

Merged
merged 1 commit into from
Feb 29, 2024

Conversation

luizgrp
Copy link
Member

@luizgrp luizgrp commented Feb 29, 2024

WHAT

Add performAction function to ReEngagePrompt.
Add sample.

WHY

So it can be used with custom prompts.

Checklist 📋

  • Add explicit visibility modifier and explicit return types for public declarations
  • Run spotless check
  • Run tests
  • Update metalava's signature text files

@luizgrp luizgrp self-assigned this Feb 29, 2024
@luizgrp luizgrp force-pushed the datalayer_reengage_performaction branch from a2e1d6a to 4341869 Compare February 29, 2024 14:19
@luizgrp luizgrp requested review from yschimke and kul3r4 February 29, 2024 14:31

if (state == ReEngageCustomPromptDemoScreenState.Idle) {
SideEffect {
viewModel.initialize()
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I understand this is correct and our guidance, it does create a lot of visual noise.

Do we know why apps like Now in Android don't follow the guidance?

https://github.com/android/nowinandroid/blob/76d0e430f7d350b1707bb19c8e007bc5679ac729/feature/bookmarks/src/main/kotlin/com/google/samples/apps/nowinandroid/feature/bookmarks/BookmarksViewModel.kt

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know, what about asking in https://github.com/android/nowinandroid/discussions ?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The answer seems to be in DAC:

Flow APIs allow for this with the started argument in the stateIn method.

Which seems to be what NiA is using.

Then it continues:

In the cases where this is inapplicable, define an idempotent initialize() function to explicitly start the state production pipeline as shown in the following snippet:

So we should re-evaluate our cases and see when the stateIn + started WhileSubscribed is applicable.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

private val reEngagePrompt: ReEngagePrompt,
) : ViewModel() {

private var initializeCalled = false
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For a follow up. Are there ways to reduce the repetition of this initialise phase?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the repetition:

Composable

        SideEffect {
            viewModel.initialize()
        }

ViewModel

        private var initializeCalled = false

        @MainThread
        fun initialize() {
            if (initializeCalled) return
            initializeCalled = true

            // pipeline initialization
        }

The repetition could be reduced having a base class for VM, but that's not scalable. I don't see many lines saved if composition approach is taken instead of inheritance.

For the composable, there is only 3 lines, that could be inlined.

Any thoughts?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nothing for us. If the guidance is good, the library should build this in.

But it seems very optional.

@luizgrp luizgrp merged commit cf62e54 into google:main Feb 29, 2024
4 checks passed
@luizgrp luizgrp deleted the datalayer_reengage_performaction branch February 29, 2024 15:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants