簡體   English   中英

Jetpack compose - 為什么 expanded() 在 ModalBottomSheet 內部?

[英]Jetpack compose - Why expanded() is internal in ModalBottomSheet?

所以我正在使用ModalBottomSheet ,引起我注意的是 sheetState 有 2 個公共方法, show()hide() for show()文檔說

 /**
     * Show the bottom sheet with animation and suspend until it's shown. If the sheet is taller
     * than 50% of the parent's height, the bottom sheet will be half expanded. Otherwise it will be
     * fully expanded.
     *
     * @throws [CancellationException] if the animation is interrupted
     */
    suspend fun show() {
        val targetValue = when {
            hasHalfExpandedState -> HalfExpanded
            else -> Expanded
        }
        animateTo(targetValue = targetValue)
    }

但是有一個問題,如果我們只是對sheetState使用.show() ,我們有時會以半滾動的底部工作表結束,這會導致與我當前的 UI 不一致

深入研究文件后,我發現我們有一個expanded()內部方法,正是我需要的

/**
 * Fully expand the bottom sheet with animation and suspend until it if fully expanded or
 * animation has been cancelled.
 * *
 * @throws [CancellationException] if the animation is interrupted
 */
internal suspend fun expand() = animateTo(Expanded)

但這恰好是內部的,不能從外部訪問

有沒有辦法用 sheetState 執行sheetState

所以,有一種方法可以做到,我們可以替換

modalBottomSheetState.show()

modalBottomSheetState.animateTo(ModalBottomSheetValue.Expanded)

這樣我們就可以確保當我們顯示模態時它會被完全展開。

我不知道為什么該方法未標記為 API 的公共方法,希望我們可以將其包含在 ModalBottomSheet 的下一個ModalBottomSheet更改中

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM