-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Add RevealOverlayInserter as an intermediate steps towards Mult…
…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
1 parent
4590259
commit 4a58dc6
Showing
19 changed files
with
502 additions
and
71 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 @@ | ||
/build |
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,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"]) | ||
} |
21 changes: 21 additions & 0 deletions
21
...mon/src/main/kotlin/com/svenjacobs/reveal/common/inserter/InPlaceRevealOverlayInserter.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,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 | ||
} |
23 changes: 23 additions & 0 deletions
23
reveal-common/src/main/kotlin/com/svenjacobs/reveal/common/inserter/RevealOverlayInserter.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,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 | ||
} |
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 @@ | ||
/build |
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,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"]) | ||
} |
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,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> |
2 changes: 1 addition & 1 deletion
2
.../reveal/internal/fullscreen/Fullscreen.kt → ...eal/compat/android/inserter/Fullscreen.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
35 changes: 35 additions & 0 deletions
35
...n/kotlin/com/svenjacobs/reveal/compat/android/inserter/FullscreenRevealOverlayInserter.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,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) | ||
} | ||
} |
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 was deleted.
Oops, something went wrong.
Oops, something went wrong.