Skip to content

Commit

Permalink
feat: Add RevealOverlayInserter as an intermediate steps towards Mult…
Browse files Browse the repository at this point in the history
…iplatform support (#60)

* feat: Add RevealOverlayInserter as an intermediate steps towards Multiplatform support

* feat: Add unbounded modifier variants with state argument

* chore: Use data object where applicable

* fix: Update documentation
  • Loading branch information
svenjacobs authored Aug 17, 2023
1 parent 4590259 commit 4a58dc6
Show file tree
Hide file tree
Showing 19 changed files with 502 additions and 71 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import com.svenjacobs.reveal.Reveal
import com.svenjacobs.reveal.RevealOverlayArrangement
import com.svenjacobs.reveal.RevealOverlayScope
import com.svenjacobs.reveal.RevealShape
import com.svenjacobs.reveal.common.inserter.InPlaceRevealOverlayInserter
import com.svenjacobs.reveal.demo.ui.theme.DemoTheme
import com.svenjacobs.reveal.rememberRevealState
import com.svenjacobs.reveal.shapes.balloon.Arrow
Expand Down Expand Up @@ -62,6 +63,7 @@ fun MainScreen(modifier: Modifier = Modifier) {
}
},
onOverlayClick = { scope.launch { revealState.hide() } },
overlayInserter = InPlaceRevealOverlayInserter(),
overlayContent = { key -> RevealOverlayContent(key) },
) {
Scaffold(
Expand Down
1 change: 1 addition & 0 deletions reveal-common/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/build
101 changes: 101 additions & 0 deletions reveal-common/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
plugins {
alias(libs.plugins.android.library)
alias(libs.plugins.jetbrains.kotlin.android)
`maven-publish`
signing
}

android {
namespace = "com.svenjacobs.reveal.common"
compileSdk = Android.compileSdk

defaultConfig {
minSdk = Android.minSdk

aarMetadata {
minCompileSdk = Android.minSdk
}

testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
}

buildTypes {
release {
isMinifyEnabled = false
proguardFiles(
getDefaultProguardFile("proguard-android-optimize.txt"),
"proguard-rules.pro",
)
}
}

compileOptions {
sourceCompatibility = JavaVersion.VERSION_11
targetCompatibility = JavaVersion.VERSION_11
}

kotlinOptions {
jvmTarget = "11"
freeCompilerArgs += "-Xexplicit-api=strict"
}

buildFeatures {
compose = true
}

composeOptions {
kotlinCompilerExtensionVersion = libs.versions.androidx.compose.compiler.get()
}

publishing {
singleVariant("release") {
withSourcesJar()
withJavadocJar()
}
}
}

dependencies {
val composeBom = platform(libs.androidx.compose.bom)

implementation(composeBom)
api(libs.androidx.compose.foundation)
api(libs.androidx.compose.ui)

debugApi(libs.androidx.compose.ui.tooling)
debugApi(libs.androidx.compose.ui.test.manifest)

testImplementation(libs.junit)
androidTestImplementation(composeBom)
androidTestImplementation(libs.androidx.test.ext.junit)
androidTestImplementation(libs.androidx.test.espresso.core)
androidTestImplementation(libs.androidx.compose.ui.test.junit4)

lintChecks(libs.slack.compose.lint.checks)
}

publishing {
publications {
register<MavenPublication>("release") {
groupId = Publication.group
version = Publication.version
artifactId = "reveal-common"

afterEvaluate {
from(components["release"])
}

pomAttributes(name = "Reveal (Common)")
}
}
}

signing {
// Store key and password in environment variables
// ORG_GRADLE_PROJECT_signingKey and ORG_GRADLE_PROJECT_signingPassword
val signingKey: String? by project
val signingPassword: String? by project
useInMemoryPgpKeys(signingKey, signingPassword)

sign(publishing.publications["release"])
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package com.svenjacobs.reveal.common.inserter

import androidx.compose.runtime.Composable
import androidx.compose.ui.unit.DpOffset

/**
* Inserts the overlay at the current position in the composition without adding any wrapper or
* other elements.
*
* This will become the default behaviour in the next major version of Reveal with support for
* Compose Multiplatform.
*/
public class InPlaceRevealOverlayInserter : RevealOverlayInserter {

@Composable
override fun Container(content: @Composable () -> Unit) {
content()
}

override val revealableOffset: DpOffset = DpOffset.Zero
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package com.svenjacobs.reveal.common.inserter

import androidx.compose.runtime.Composable
import androidx.compose.ui.unit.DpOffset

/**
* Defines a strategy of how to insert the overlay into the composition.
*/
public interface RevealOverlayInserter {

/**
* Container which is used to insert the overlay.
*
* @param content Overlay composable
*/
@Composable
public fun Container(content: @Composable () -> Unit)

/**
* Additional offset that is applied to all revealables when this inserter is used.
*/
public val revealableOffset: DpOffset
}
1 change: 1 addition & 0 deletions reveal-compat-android/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/build
107 changes: 107 additions & 0 deletions reveal-compat-android/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
plugins {
alias(libs.plugins.android.library)
alias(libs.plugins.jetbrains.kotlin.android)
`maven-publish`
signing
}

android {
namespace = "com.svenjacobs.reveal.compat.android"
compileSdk = Android.compileSdk

defaultConfig {
minSdk = Android.minSdk

aarMetadata {
minCompileSdk = Android.minSdk
}

testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
}

buildTypes {
release {
isMinifyEnabled = false
proguardFiles(
getDefaultProguardFile("proguard-android-optimize.txt"),
"proguard-rules.pro",
)
}
}

compileOptions {
sourceCompatibility = JavaVersion.VERSION_11
targetCompatibility = JavaVersion.VERSION_11
}

kotlinOptions {
jvmTarget = "11"
freeCompilerArgs += "-Xexplicit-api=strict"
}

buildFeatures {
compose = true
}

composeOptions {
kotlinCompilerExtensionVersion = libs.versions.androidx.compose.compiler.get()
}

publishing {
singleVariant("release") {
withSourcesJar()
withJavadocJar()
}
}

lint {
baseline = file("lint-baseline.xml")
}
}

dependencies {
api(project(":reveal-common"))

val composeBom = platform(libs.androidx.compose.bom)

implementation(composeBom)
api(libs.androidx.compose.foundation)
api(libs.androidx.compose.ui)

debugApi(libs.androidx.compose.ui.tooling)
debugApi(libs.androidx.compose.ui.test.manifest)

testImplementation(libs.junit)
androidTestImplementation(composeBom)
androidTestImplementation(libs.androidx.test.ext.junit)
androidTestImplementation(libs.androidx.test.espresso.core)
androidTestImplementation(libs.androidx.compose.ui.test.junit4)

lintChecks(libs.slack.compose.lint.checks)
}

publishing {
publications {
register<MavenPublication>("release") {
groupId = Publication.group
version = Publication.version
artifactId = "reveal-compat-android"

afterEvaluate {
from(components["release"])
}

pomAttributes(name = "Reveal (Compat Android)")
}
}
}

signing {
// Store key and password in environment variables
// ORG_GRADLE_PROJECT_signingKey and ORG_GRADLE_PROJECT_signingPassword
val signingKey: String? by project
val signingPassword: String? by project
useInMemoryPgpKeys(signingKey, signingPassword)

sign(publishing.publications["release"])
}
15 changes: 15 additions & 0 deletions reveal-compat-android/lint-baseline.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?xml version="1.0" encoding="UTF-8"?>
<issues format="6" by="lint 8.0.2" type="baseline" client="gradle" dependencies="false" name="AGP (8.0.2)" variant="all" version="8.0.2">

<issue
id="RememberReturnType"
message="`remember` calls must not return `Unit`"
errorLine1=" val composeView = remember {"
errorLine2=" ~~~~~~~~">
<location
file="src/main/kotlin/com/svenjacobs/reveal/compat/android/inserter/Fullscreen.kt"
line="23"
column="20"/>
</issue>

</issues>
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.svenjacobs.reveal.internal.fullscreen
package com.svenjacobs.reveal.compat.android.inserter

import android.app.Activity
import android.content.Context
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package com.svenjacobs.reveal.compat.android.inserter

import androidx.compose.runtime.Composable
import androidx.compose.ui.platform.ComposeView
import androidx.compose.ui.unit.DpOffset
import com.svenjacobs.reveal.common.inserter.InPlaceRevealOverlayInserter
import com.svenjacobs.reveal.common.inserter.RevealOverlayInserter

/**
* Inserts the overlay into a new [ComposeView] which is added to Android's root content view.
* Thereby the effect is rendered "full screen" regardless where the `Reveal` composable is added
* in the composition.
*
* In order to ensure compatibility with Compose Multiplatform in the future, it is recommended
* to **not** use this inserter but use [InPlaceRevealOverlayInserter] in apps written fully in
* Compose.
*
* @param revealableOffset Additional offset which is applied to all revealables when using this
* inserter. Should be used to correct misplaced reveal effects where the
* root composables and root content view do not match, e.g. in applications
* that use `ComposeView` in legacy Android views. Use negative values to
* offset towards [0,0] of the coordinate system.
*
* @see Fullscreen
* @see InPlaceRevealOverlayInserter
*/
public class FullscreenRevealOverlayInserter(
override val revealableOffset: DpOffset = DpOffset.Zero,
) : RevealOverlayInserter {

@Composable
override fun Container(content: @Composable () -> Unit) {
Fullscreen(content = content)
}
}
7 changes: 3 additions & 4 deletions reveal-core/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -54,13 +54,12 @@ android {
withJavadocJar()
}
}

lint {
baseline = file("lint-baseline.xml")
}
}

dependencies {
api(project(":reveal-common"))
api(project(":reveal-compat-android"))

val composeBom = platform(libs.androidx.compose.bom)

implementation(composeBom)
Expand Down
12 changes: 0 additions & 12 deletions reveal-core/lint-baseline.xml

This file was deleted.

Loading

0 comments on commit 4a58dc6

Please sign in to comment.