Skip to content
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

Expect insets in common #586

Merged
merged 5 commits into from
Jun 9, 2023
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 5 additions & 0 deletions compose/foundation/foundation-layout/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,11 @@ if(AndroidXComposePlugin.isMultiplatformEnabled(project)) {

jsWasmMain.dependsOn(jsNativeMain)

notMobileMain.dependsOn(commonMain)
desktopMain.dependsOn(notMobileMain)
macosMain.dependsOn(notMobileMain)
jsWasmMain.dependsOn(notMobileMain)

jsMain {
dependsOn(jsWasmMain)
dependencies {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ var ComposeView.consumeWindowInsets: Boolean
/**
* For the [WindowInsetsCompat.Type.captionBar].
*/
val WindowInsets.Companion.captionBar: WindowInsets
actual val WindowInsets.Companion.captionBar: WindowInsets
@Composable
@NonRestartableComposable
get() = WindowInsetsHolder.current().captionBar
Expand All @@ -129,7 +129,7 @@ val WindowInsets.Companion.captionBar: WindowInsets
* For the [WindowInsetsCompat.Type.displayCutout]. This insets represents the area that the
* display cutout (e.g. for camera) is and important content should be excluded from.
*/
val WindowInsets.Companion.displayCutout: WindowInsets
actual val WindowInsets.Companion.displayCutout: WindowInsets
@Composable
@NonRestartableComposable
get() = WindowInsetsHolder.current().displayCutout
Expand All @@ -143,7 +143,7 @@ val WindowInsets.Companion.displayCutout: WindowInsets
* `AndroidManifest.xml` file and call `WindowCompat.setDecorFitsSystemWindows(window, false)`
* in their [android.app.Activity.onCreate].
*/
val WindowInsets.Companion.ime: WindowInsets
actual val WindowInsets.Companion.ime: WindowInsets
@Composable
@NonRestartableComposable
get() = WindowInsetsHolder.current().ime
Expand All @@ -152,7 +152,7 @@ val WindowInsets.Companion.ime: WindowInsets
* For the [WindowInsetsCompat.Type.mandatorySystemGestures]. These insets represents the
* space where system gestures have priority over application gestures.
*/
val WindowInsets.Companion.mandatorySystemGestures: WindowInsets
actual val WindowInsets.Companion.mandatorySystemGestures: WindowInsets
@Composable
@NonRestartableComposable
get() = WindowInsetsHolder.current().mandatorySystemGestures
Expand All @@ -162,47 +162,47 @@ val WindowInsets.Companion.mandatorySystemGestures: WindowInsets
* system UI places navigation bars. Interactive UI should avoid the navigation bars
* area.
*/
val WindowInsets.Companion.navigationBars: WindowInsets
actual val WindowInsets.Companion.navigationBars: WindowInsets
@Composable
@NonRestartableComposable
get() = WindowInsetsHolder.current().navigationBars

/**
* For the [WindowInsetsCompat.Type.statusBars].
*/
val WindowInsets.Companion.statusBars: WindowInsets
actual val WindowInsets.Companion.statusBars: WindowInsets
@Composable
@NonRestartableComposable
get() = WindowInsetsHolder.current().statusBars

/**
* For the [WindowInsetsCompat.Type.systemBars].
*/
val WindowInsets.Companion.systemBars: WindowInsets
actual val WindowInsets.Companion.systemBars: WindowInsets
@Composable
@NonRestartableComposable
get() = WindowInsetsHolder.current().systemBars

/**
* For the [WindowInsetsCompat.Type.systemGestures].
*/
val WindowInsets.Companion.systemGestures: WindowInsets
actual val WindowInsets.Companion.systemGestures: WindowInsets
@Composable
@NonRestartableComposable
get() = WindowInsetsHolder.current().systemGestures

/**
* For the [WindowInsetsCompat.Type.tappableElement].
*/
val WindowInsets.Companion.tappableElement: WindowInsets
actual val WindowInsets.Companion.tappableElement: WindowInsets
@Composable
@NonRestartableComposable
get() = WindowInsetsHolder.current().tappableElement

/**
* The insets for the curved areas in a waterfall display.
*/
val WindowInsets.Companion.waterfall: WindowInsets
actual val WindowInsets.Companion.waterfall: WindowInsets
@Composable
@NonRestartableComposable
get() = WindowInsetsHolder.current().waterfall
Expand All @@ -212,7 +212,7 @@ val WindowInsets.Companion.waterfall: WindowInsets
* This includes all [system bars][systemBars], [display cutout][displayCutout], and
* [soft keyboard][ime].
*/
val WindowInsets.Companion.safeDrawing: WindowInsets
actual val WindowInsets.Companion.safeDrawing: WindowInsets
@Composable
@NonRestartableComposable
get() = WindowInsetsHolder.current().safeDrawing
Expand All @@ -223,7 +223,7 @@ val WindowInsets.Companion.safeDrawing: WindowInsets
* [mandatory system gestures][mandatorySystemGestures],
* [rounded display areas][waterfall], and [tappable areas][tappableElement].
*/
val WindowInsets.Companion.safeGestures: WindowInsets
actual val WindowInsets.Companion.safeGestures: WindowInsets
@Composable
@NonRestartableComposable
get() = WindowInsetsHolder.current().safeGestures
Expand All @@ -232,7 +232,7 @@ val WindowInsets.Companion.safeGestures: WindowInsets
* The insets that include all areas that may be drawn over or have gesture confusion,
* including everything in [safeDrawing] and [safeGestures].
*/
val WindowInsets.Companion.safeContent: WindowInsets
actual val WindowInsets.Companion.safeContent: WindowInsets
@Composable
@NonRestartableComposable
get() = WindowInsetsHolder.current().safeContent
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -671,3 +671,37 @@ private class InsetsPaddingValues(
return result
}
}

/**
* An insets type representing the window of a caption bar.
*/
expect val WindowInsets.Companion.captionBar: WindowInsets

/**
* This [WindowInsets] represents the area with the display cutout (e.g. for camera).
*/
expect val WindowInsets.Companion.displayCutout: WindowInsets

expect val WindowInsets.Companion.ime: WindowInsets

expect val WindowInsets.Companion.mandatorySystemGestures: WindowInsets

expect val WindowInsets.Companion.navigationBars: WindowInsets

expect val WindowInsets.Companion.statusBars: WindowInsets

expect val WindowInsets.Companion.systemBars: WindowInsets

expect val WindowInsets.Companion.systemGestures: WindowInsets

expect val WindowInsets.Companion.tappableElement: WindowInsets

expect val WindowInsets.Companion.waterfall: WindowInsets

expect val WindowInsets.Companion.safeDrawing: WindowInsets

expect val WindowInsets.Companion.safeGestures: WindowInsets

expect val WindowInsets.Companion.safeContent: WindowInsets


Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
/*
* Copyright 2023 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package androidx.compose.foundation.layout

private val ZeroInsets = WindowInsets(0, 0, 0, 0)

actual val WindowInsets.Companion.captionBar: WindowInsets
get() = ZeroInsets

actual val WindowInsets.Companion.displayCutout: WindowInsets
get() = ZeroInsets

actual val WindowInsets.Companion.ime: WindowInsets
get() = ZeroInsets

actual val WindowInsets.Companion.mandatorySystemGestures: WindowInsets
get() = ZeroInsets

actual val WindowInsets.Companion.navigationBars: WindowInsets
get() = ZeroInsets

actual val WindowInsets.Companion.statusBars: WindowInsets
get() = ZeroInsets

actual val WindowInsets.Companion.systemBars: WindowInsets
get() = ZeroInsets

actual val WindowInsets.Companion.systemGestures: WindowInsets
get() = ZeroInsets

actual val WindowInsets.Companion.tappableElement: WindowInsets
get() = ZeroInsets

actual val WindowInsets.Companion.waterfall: WindowInsets
get() = ZeroInsets

actual val WindowInsets.Companion.safeDrawing: WindowInsets
get() = ZeroInsets

actual val WindowInsets.Companion.safeGestures: WindowInsets
get() = ZeroInsets

actual val WindowInsets.Companion.safeContent: WindowInsets
get() = ZeroInsets
Original file line number Diff line number Diff line change
Expand Up @@ -53,12 +53,13 @@ private val WindowInsets.Companion.layoutMargins: WindowInsets
* An insets type representing the window of a caption bar.
* It is useless for iOS.
*/
val WindowInsets.Companion.captionBar get() = ZeroInsets
actual val WindowInsets.Companion.captionBar: WindowInsets
get() = ZeroInsets

/**
* This [WindowInsets] represents the area with the display cutout (e.g. for camera).
*/
val WindowInsets.Companion.displayCutout: WindowInsets
actual val WindowInsets.Companion.displayCutout: WindowInsets
@Composable
@OptIn(InternalComposeApi::class)
get() = when (LocalInterfaceOrientationState.current.value) {
Expand All @@ -74,30 +75,30 @@ val WindowInsets.Companion.displayCutout: WindowInsets
*
* TODO: Animation doesn't work on iOS yet
*/
val WindowInsets.Companion.ime: WindowInsets
actual val WindowInsets.Companion.ime: WindowInsets
@Composable
@OptIn(InternalComposeApi::class)
get() = WindowInsets(bottom = LocalKeyboardOverlapHeightState.current.value.dp)

/**
* These insets represents the space where system gestures have priority over application gestures.
* These insets represent the space where system gestures have priority over application gestures.
*/
val WindowInsets.Companion.mandatorySystemGestures: WindowInsets
actual val WindowInsets.Companion.mandatorySystemGestures: WindowInsets
@Composable
get() = iosSafeArea.only(WindowInsetsSides.Top + WindowInsetsSides.Bottom)

/**
* These insets represent where system UI places navigation bars.
* Interactive UI should avoid the navigation bars area.
*/
val WindowInsets.Companion.navigationBars: WindowInsets
actual val WindowInsets.Companion.navigationBars: WindowInsets
@Composable
get() = iosSafeArea.only(WindowInsetsSides.Bottom)

/**
* These insets represents status bar.
* These insets represent status bar.
*/
val WindowInsets.Companion.statusBars: WindowInsets
actual val WindowInsets.Companion.statusBars: WindowInsets
@Composable
@OptIn(InternalComposeApi::class)
get() = when (LocalInterfaceOrientationState.current.value) {
Expand All @@ -106,10 +107,10 @@ val WindowInsets.Companion.statusBars: WindowInsets
}

/**
* These insets represents all system bars.
* These insets represent all system bars.
* Includes [statusBars], [captionBar] as well as [navigationBars], but not [ime].
*/
val WindowInsets.Companion.systemBars: WindowInsets
actual val WindowInsets.Companion.systemBars: WindowInsets
@Composable
get() = iosSafeArea

Expand All @@ -118,44 +119,44 @@ val WindowInsets.Companion.systemBars: WindowInsets
* priority and may consume some or all touch input, e.g. due to the system bar
* occupying it, or it being reserved for touch-only gestures.
*/
val WindowInsets.Companion.systemGestures: WindowInsets
actual val WindowInsets.Companion.systemGestures: WindowInsets
@Composable
get() = layoutMargins // the same as iosSafeArea.add(WindowInsets(left = 16.dp, right = 16.dp))

/**
* Returns the tappable element insets.
*/
val WindowInsets.Companion.tappableElement: WindowInsets
actual val WindowInsets.Companion.tappableElement: WindowInsets
@Composable
get() = iosSafeArea.only(WindowInsetsSides.Top)

/**
* The insets for the curved areas in a waterfall display.
* It is useless for iOS.
*/
val WindowInsets.Companion.waterfall: WindowInsets get() = ZeroInsets
actual val WindowInsets.Companion.waterfall: WindowInsets get() = ZeroInsets

/**
* The insets that include areas where content may be covered by other drawn content.
* This includes all [systemBars], [displayCutout], and [ime].
*/
val WindowInsets.Companion.safeDrawing
actual val WindowInsets.Companion.safeDrawing: WindowInsets
@Composable
get() = systemBars.union(ime).union(displayCutout)

/**
* The insets that include areas where gestures may be confused with other input,
* including [systemGestures], [mandatorySystemGestures], [waterfall], and [tappableElement].
*/
val WindowInsets.Companion.safeGestures: WindowInsets
actual val WindowInsets.Companion.safeGestures: WindowInsets
@Composable
get() = tappableElement.union(mandatorySystemGestures).union(systemGestures).union(waterfall)

/**
* The insets that include all areas that may be drawn over or have gesture confusion,
* including everything in [safeDrawing] and [safeGestures].
*/
val WindowInsets.Companion.safeContent: WindowInsets
actual val WindowInsets.Companion.safeContent: WindowInsets
@Composable
get() = safeDrawing.union(safeGestures)