美文网首页
ComposeDestinations 带参数返回

ComposeDestinations 带参数返回

作者: 肖散 | 来源:发表于2023-12-25 16:14 被阅读0次

    ComposeDestinations

    发起方 XXX

    通过使用ResultRecipient参数来实现注册回调监听。

    @Destination
    @Composable
    fun XXX(
        navigator: DestinationsNavigator = EmptyDestinationsNavigator,
        result: ResultRecipient<YYYDestination, String> = EmptyResultRecipient(),
    ) {
        result.onNavResult {
            EchoLog.log("resultRecipient", it)
            when (it) {
                is NavResult.Canceled -> {}
                is NavResult.Value -> { 
                           //----
                     }
                }
            }
        }
    

    返回方YYY

    通过ResultBackNavigator来实现数据回传

    @Destination
    @Composable
    fun YYY(
        navigator: DestinationsNavigator = EmptyDestinationsNavigator,
        resultBackNavigator: ResultBackNavigator<String> = EmptyResultBackNavigator()
    ) {
      //在需要返回的地方
      resultBackNavigator.navigateBack("ans")
    }
    

    相关文章

      网友评论

          本文标题:ComposeDestinations 带参数返回

          本文链接:https://www.haomeiwen.com/subject/jaekndtx.html