Skip to content

Conversation

@rjrjr
Copy link
Collaborator

@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 a team and zach-klippenstein 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.

3 participants