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

[Adaptive] Add accompanist/adaptive library with TwoPane implementation. #1281

Merged
merged 11 commits into from Aug 11, 2022
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/
39 changes: 39 additions & 0 deletions adaptive/api/current.api
@@ -0,0 +1,39 @@
// Signature format: 4.0
package com.google.accompanist.adaptive {

public final class SplitResult {
ctor public SplitResult(boolean isHorizontalSplit, androidx.compose.ui.geometry.Rect gapBounds);
method public androidx.compose.ui.geometry.Rect getGapBounds();
method public boolean isHorizontalSplit();
property public final androidx.compose.ui.geometry.Rect gapBounds;
property public final boolean isHorizontalSplit;
}

public final class TwoPaneKt {
method public static com.google.accompanist.adaptive.TwoPaneStrategy HorizontalTwoPaneStrategy(com.google.accompanist.adaptive.WindowGeometry windowGeometry, com.google.accompanist.adaptive.TwoPaneStrategy defaultStrategy);
method public static com.google.accompanist.adaptive.TwoPaneStrategy HorizontalTwoPaneStrategy(com.google.accompanist.adaptive.WindowGeometry windowGeometry, float splitFraction, optional float gapWidth);
method public static com.google.accompanist.adaptive.TwoPaneStrategy HorizontalTwoPaneStrategy(com.google.accompanist.adaptive.WindowGeometry windowGeometry, float splitOffset, 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, optional androidx.compose.ui.Modifier modifier);
method public static com.google.accompanist.adaptive.TwoPaneStrategy TwoPaneStrategy(com.google.accompanist.adaptive.WindowGeometry windowGeometry, com.google.accompanist.adaptive.TwoPaneStrategy defaultStrategy);
method public static com.google.accompanist.adaptive.TwoPaneStrategy VerticalTwoPaneStrategy(com.google.accompanist.adaptive.WindowGeometry windowGeometry, com.google.accompanist.adaptive.TwoPaneStrategy defaultStrategy);
method public static com.google.accompanist.adaptive.TwoPaneStrategy VerticalTwoPaneStrategy(com.google.accompanist.adaptive.WindowGeometry windowGeometry, float splitFraction, optional float gapHeight);
method public static com.google.accompanist.adaptive.TwoPaneStrategy VerticalTwoPaneStrategy(com.google.accompanist.adaptive.WindowGeometry windowGeometry, float splitOffset, 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);
}

public interface WindowGeometry {
method public java.util.List<androidx.window.layout.DisplayFeature> getDisplayFeatures();
method public androidx.compose.material3.windowsizeclass.WindowSizeClass getWindowSizeClass();
property public abstract java.util.List<androidx.window.layout.DisplayFeature> displayFeatures;
property public abstract androidx.compose.material3.windowsizeclass.WindowSizeClass windowSizeClass;
}

public final class WindowGeometryKt {
method @androidx.compose.runtime.Composable public static com.google.accompanist.adaptive.WindowGeometry calculateWindowGeometry(android.app.Activity activity);
}

}

120 changes: 120 additions & 0 deletions adaptive/build.gradle
@@ -0,0 +1,120 @@
/*
* 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.compose.material3.windowSizeClass
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>