Skip to content

Commit

Permalink
Merge pull request #1281 from google/av/adaptive-two-pane
Browse files Browse the repository at this point in the history
[Adaptive] Add accompanist/adaptive library with TwoPane implementation.
  • Loading branch information
alexvanyo committed Aug 11, 2022
2 parents d116183 + fe020d8 commit 3e99592
Show file tree
Hide file tree
Showing 19 changed files with 2,802 additions and 0 deletions.
3 changes: 3 additions & 0 deletions README.md
Expand Up @@ -62,6 +62,9 @@ A library that provides a layout implementing the swipe-to-refresh UX pattern, s
### 🌏 [Web](./web/)
A wrapper around WebView for basic WebView support in Jetpack Compose.

### 📜 [Adaptive](./adaptive/)
A library providing a collection of utilities for adaptive layouts.

### 📐 [Insets](./insets/) (Deprecated)
See our [Migration Guide](https://google.github.io/accompanist/insets/) for migrating to Insets in Compose.

Expand Down
21 changes: 21 additions & 0 deletions adaptive/README.md
@@ -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/
42 changes: 42 additions & 0 deletions adaptive/api/current.api
@@ -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);
}

}

119 changes: 119 additions & 0 deletions adaptive/build.gradle
@@ -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"
3 changes: 3 additions & 0 deletions adaptive/gradle.properties
@@ -0,0 +1,3 @@
POM_ARTIFACT_ID=accompanist-adaptive
POM_NAME=Accompanist Adaptive library
POM_PACKAGING=aar
18 changes: 18 additions & 0 deletions adaptive/src/main/AndroidManifest.xml
@@ -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>
@@ -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
}

0 comments on commit 3e99592

Please sign in to comment.