Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1281 from google/av/adaptive-two-pane
[Adaptive] Add accompanist/adaptive library with TwoPane implementation.
- Loading branch information
Showing
19 changed files
with
2,802 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
# Adaptive utilities for Jetpack Compose | ||
|
||
[![Maven Central](https://img.shields.io/maven-central/v/com.google.accompanist/accompanist-adaptive)](https://search.maven.org/search?q=g:com.google.accompanist) | ||
|
||
For more information, visit the documentation: https://google.github.io/accompanist/adaptive | ||
|
||
## Download | ||
|
||
```groovy | ||
repositories { | ||
mavenCentral() | ||
} | ||
dependencies { | ||
implementation "com.google.accompanist:accompanist-adaptive:<version>" | ||
} | ||
``` | ||
|
||
Snapshots of the development version are available in [Sonatype's `snapshots` repository][snap]. These are updated on every commit. | ||
|
||
[snap]: https://oss.sonatype.org/content/repositories/snapshots/com/google/accompanist/accompanist-adaptive/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
// Signature format: 4.0 | ||
package com.google.accompanist.adaptive { | ||
|
||
public final class DisplayFeaturesKt { | ||
method @androidx.compose.runtime.Composable public static java.util.List<androidx.window.layout.DisplayFeature> calculateDisplayFeatures(android.app.Activity activity); | ||
} | ||
|
||
@kotlin.jvm.JvmInline public final class FoldAwareConfiguration { | ||
field public static final com.google.accompanist.adaptive.FoldAwareConfiguration.Companion Companion; | ||
} | ||
|
||
public static final class FoldAwareConfiguration.Companion { | ||
method public int getAllFolds(); | ||
method public int getHorizontalFoldsOnly(); | ||
method public int getVerticalFoldsOnly(); | ||
property public final int AllFolds; | ||
property public final int HorizontalFoldsOnly; | ||
property public final int VerticalFoldsOnly; | ||
} | ||
|
||
public final class SplitResult { | ||
ctor public SplitResult(androidx.compose.foundation.gestures.Orientation gapOrientation, androidx.compose.ui.geometry.Rect gapBounds); | ||
method public androidx.compose.ui.geometry.Rect getGapBounds(); | ||
method public androidx.compose.foundation.gestures.Orientation getGapOrientation(); | ||
property public final androidx.compose.ui.geometry.Rect gapBounds; | ||
property public final androidx.compose.foundation.gestures.Orientation gapOrientation; | ||
} | ||
|
||
public final class TwoPaneKt { | ||
method public static com.google.accompanist.adaptive.TwoPaneStrategy HorizontalTwoPaneStrategy(float splitFraction, optional float gapWidth); | ||
method public static com.google.accompanist.adaptive.TwoPaneStrategy HorizontalTwoPaneStrategy(float splitOffset, optional boolean offsetFromStart, optional float gapWidth); | ||
method @androidx.compose.runtime.Composable public static void TwoPane(kotlin.jvm.functions.Function0<kotlin.Unit> first, kotlin.jvm.functions.Function0<kotlin.Unit> second, com.google.accompanist.adaptive.TwoPaneStrategy strategy, java.util.List<? extends androidx.window.layout.DisplayFeature> displayFeatures, optional androidx.compose.ui.Modifier modifier, optional int foldAwareConfiguration); | ||
method public static com.google.accompanist.adaptive.TwoPaneStrategy VerticalTwoPaneStrategy(float splitFraction, optional float gapHeight); | ||
method public static com.google.accompanist.adaptive.TwoPaneStrategy VerticalTwoPaneStrategy(float splitOffset, optional boolean offsetFromTop, optional float gapHeight); | ||
} | ||
|
||
public fun interface TwoPaneStrategy { | ||
method public com.google.accompanist.adaptive.SplitResult calculateSplitResult(androidx.compose.ui.unit.Density density, androidx.compose.ui.unit.LayoutDirection layoutDirection, androidx.compose.ui.layout.LayoutCoordinates layoutCoordinates); | ||
} | ||
|
||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,119 @@ | ||
/* | ||
* Copyright 2022 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 | ||
* | ||
* https://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. | ||
*/ | ||
|
||
plugins { | ||
id 'com.android.library' | ||
id 'kotlin-android' | ||
id 'org.jetbrains.dokka' | ||
} | ||
|
||
kotlin { | ||
explicitApi() | ||
} | ||
|
||
android { | ||
compileSdkVersion 33 | ||
|
||
defaultConfig { | ||
minSdkVersion 21 | ||
// targetSdkVersion has no effect for libraries. This is only used for the test APK | ||
targetSdkVersion 32 | ||
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" | ||
} | ||
|
||
compileOptions { | ||
sourceCompatibility JavaVersion.VERSION_1_8 | ||
targetCompatibility JavaVersion.VERSION_1_8 | ||
} | ||
|
||
buildFeatures { | ||
buildConfig false | ||
compose true | ||
} | ||
|
||
composeOptions { | ||
kotlinCompilerExtensionVersion libs.versions.composeCompiler.get() | ||
} | ||
|
||
lintOptions { | ||
textReport true | ||
textOutput 'stdout' | ||
// We run a full lint analysis as build part in CI, so skip vital checks for assemble tasks | ||
checkReleaseBuilds false | ||
} | ||
|
||
packagingOptions { | ||
// Some of the META-INF files conflict with coroutines-test. Exclude them to enable | ||
// our test APK to build (has no effect on our AARs) | ||
excludes += "/META-INF/AL2.0" | ||
excludes += "/META-INF/LGPL2.1" | ||
} | ||
|
||
testOptions { | ||
unitTests { | ||
includeAndroidResources = true | ||
} | ||
animationsDisabled true | ||
} | ||
|
||
sourceSets { | ||
test { | ||
java.srcDirs += 'src/sharedTest/kotlin' | ||
res.srcDirs += 'src/sharedTest/res' | ||
} | ||
androidTest { | ||
java.srcDirs += 'src/sharedTest/kotlin' | ||
res.srcDirs += 'src/sharedTest/res' | ||
} | ||
} | ||
} | ||
|
||
dependencies { | ||
api libs.compose.foundation.foundation | ||
api libs.compose.ui.ui | ||
api libs.androidx.window | ||
|
||
implementation libs.napier | ||
|
||
// ====================== | ||
// Test dependencies | ||
// ====================== | ||
|
||
androidTestImplementation project(':internal-testutils') | ||
testImplementation project(':internal-testutils') | ||
|
||
androidTestImplementation libs.junit | ||
testImplementation libs.junit | ||
|
||
androidTestImplementation libs.truth | ||
testImplementation libs.truth | ||
|
||
androidTestImplementation libs.compose.ui.test.junit4 | ||
testImplementation libs.compose.ui.test.junit4 | ||
|
||
androidTestImplementation libs.compose.ui.test.manifest | ||
testImplementation libs.compose.ui.test.manifest | ||
|
||
androidTestImplementation libs.androidx.test.runner | ||
testImplementation libs.androidx.test.runner | ||
|
||
androidTestImplementation libs.androidx.window.testing | ||
testImplementation libs.androidx.window.testing | ||
|
||
testImplementation libs.robolectric | ||
} | ||
|
||
apply plugin: "com.vanniktech.maven.publish" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
POM_ARTIFACT_ID=accompanist-adaptive | ||
POM_NAME=Accompanist Adaptive library | ||
POM_PACKAGING=aar |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
<!-- | ||
~ Copyright 2022 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 | ||
~ | ||
~ https://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. | ||
--> | ||
|
||
<manifest package="com.google.accompanist.adaptive"> | ||
</manifest> |
44 changes: 44 additions & 0 deletions
44
adaptive/src/main/java/com/google/accompanist/adaptive/DisplayFeatures.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
/* | ||
* Copyright 2022 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 | ||
* | ||
* https://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 com.google.accompanist.adaptive | ||
|
||
import android.app.Activity | ||
import androidx.compose.runtime.Composable | ||
import androidx.compose.runtime.getValue | ||
import androidx.compose.runtime.produceState | ||
import androidx.compose.runtime.remember | ||
import androidx.window.layout.DisplayFeature | ||
import androidx.window.layout.WindowInfoTracker | ||
|
||
/** | ||
* Calculates the list of [DisplayFeature]s from the given [activity]. | ||
*/ | ||
@Composable | ||
public fun calculateDisplayFeatures(activity: Activity): List<DisplayFeature> { | ||
val windowInfoTracker = remember(activity) { WindowInfoTracker.getOrCreate(activity) } | ||
val windowLayoutInfo = remember(windowInfoTracker, activity) { | ||
windowInfoTracker.windowLayoutInfo(activity) | ||
} | ||
|
||
val displayFeatures by produceState(initialValue = emptyList<DisplayFeature>()) { | ||
windowLayoutInfo.collect { info -> | ||
value = info.displayFeatures | ||
} | ||
} | ||
|
||
return displayFeatures | ||
} |
Oops, something went wrong.