override fun popState()

in android/libraries/rib-router-navigator/src/main/kotlin/com/uber/rib/core/StackRouterNavigator.kt [42:82]


  override fun popState() {
    // If we are in a transient state, go ahead and pop that state.
    var fromState: RouterAndState<*, StateT>? = null
    if (currentTransientRouterAndState != null) {
      fromState = currentTransientRouterAndState
      val fromRouterName = fromState?.router?.javaClass?.simpleName
      currentTransientRouterAndState = null
      log(
        String.format(
          Locale.getDefault(),
          "Preparing to pop existing transient state for router: %s",
          fromRouterName,
        ),
      )
    } else {
      if (!navigationStack.isEmpty()) {
        fromState = navigationStack.pop()
        val fromRouterName: String = fromState.router.javaClass.simpleName
        log(
          String.format(
            Locale.getDefault(),
            "Preparing to pop existing state for router: %s",
            fromRouterName,
          ),
        )
      }
    }
    if (fromState != null) {
      // Pull the incoming state (So we can restore it.)
      var toState: RouterAndState<*, StateT>? = null
      if (!navigationStack.isEmpty()) {
        toState = navigationStack.peek()
      }
      detachInternal(fromState, toState?.state, false)
      if (toState != null) {
        attachInternal(fromState, toState, false)
      }
    } else {
      log("No state to pop. No action will be taken.")
    }
  }