Skip to content

Punches up composite rendering API and demonstrates nav logging. #1309

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

Merged
merged 1 commit into from
May 9, 2025

Conversation

rjrjr
Copy link
Contributor

@rjrjr rjrjr commented May 9, 2025

Introduces a few interfaces to make it easier to navigate composite rendering structures, useful for both production logging and workflow unit testing.

Updates some samples (hellobackbutton, ravenapp and poetryapp) to demonstrate their use for navigation logging.

For example, from this naive snippet in HelloBackButtonActivity:

    }.onEach {
      Timber.i("Navigated to %s", it.unwrap())
    }

we get this very useful logcat:

Navigated to HelloBackButtonScreen(message=Able, onClick=Function0<kotlin.Unit>, onBackPressed=null)
Navigated to HelloBackButtonScreen(message=Baker, onClick=Function0<kotlin.Unit>, onBackPressed=Function0<kotlin.Unit>)
Navigated to HelloBackButtonScreen(message=Charlie, onClick=Function0<kotlin.Unit>, onBackPressed=Function0<kotlin.Unit>)
Navigated to HelloBackButtonScreen(message=Baker, onClick=Function0<kotlin.Unit>, onBackPressed=Function0<kotlin.Unit>)
Navigated to HelloBackButtonScreen(message=Able, onClick=Function0<kotlin.Unit>, onBackPressed=null)
Navigated to AlertOverlay(buttons={POSITIVE=I'm Positive, NEGATIVE=Negatory}, message=Are you sure you want to do this thing?, title=, cancelable=true, onEvent=Function1<com.squareup.workflow1.ui.navigation.AlertOverlay$Event, kotlin.Unit>)

Emphasis on "naive". To keep the samples simple I didn't debounce anything, so in a more complex app you'd actually see a "Navigate to…" each time you update something in place. But that's a trivial fix:

    ).onEach {
      NavLogger.log(it)
    }
  }

  private object NavLogger {
    var lastKey = ""

    fun log(dest: Any) {
      val unwrapped = dest.unwrap()
      Compatible.keyFor(unwrapped).takeIf { it != lastKey }?.let { newKey ->
        Timber.i("Navigated to: %s", unwrapped)
        lastKey = newKey
      }
    }
  }

@rjrjr rjrjr requested review from zach-klippenstein and a team as code owners May 9, 2025 22:41
@rjrjr rjrjr force-pushed the ray/unwrap branch 3 times, most recently from d430002 to 2da9c21 Compare May 9, 2025 22:53
Introduces a few interfaces to make it easier to navigate composite rendering structures, useful for both production logging and workflow unit testing.

Updates some samples (hellobackbutton, ravenapp and poetryapp) to demonstrate their use for navigation logging.
@rjrjr rjrjr merged commit 54e0b46 into main May 9, 2025
42 checks passed
@rjrjr rjrjr deleted the ray/unwrap branch May 9, 2025 23:29
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