-
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.
fix: click modifier not working after config change (#130)
* chore: add example app for easier debugging * fix: click modifier not working after config change (issue #127)
- Loading branch information
1 parent
18f3b57
commit 5da581a
Showing
13 changed files
with
259 additions
and
2 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
*.iml | ||
.gradle | ||
.idea | ||
!.idea/runConfigurations | ||
.DS_Store | ||
build | ||
captures | ||
|
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 |
---|---|---|
@@ -1,2 +1,19 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<manifest /> | ||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"> | ||
|
||
<application | ||
android:name=".App" | ||
android:allowBackup="false" | ||
android:supportsRtl="true" | ||
android:theme="@style/AppTheme"> | ||
<activity | ||
android:name=".MainActivity" | ||
android:exported="true"> | ||
<intent-filter> | ||
<action android:name="android.intent.action.MAIN" /> | ||
<category android:name="android.intent.category.LAUNCHER" /> | ||
</intent-filter> | ||
</activity> | ||
</application> | ||
|
||
</manifest> |
Empty file.
14 changes: 14 additions & 0 deletions
14
android-tests/src/main/kotlin/com/svenjacobs/reveal/android/tests/App.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,14 @@ | ||
package com.svenjacobs.reveal.android.tests | ||
|
||
import android.app.Application | ||
import android.util.Log | ||
import com.svenjacobs.reveal.common.internal.log.Logger | ||
|
||
class App : Application() { | ||
|
||
override fun onCreate() { | ||
super.onCreate() | ||
|
||
Logger.adapter = Logger.Adapter { message, tag -> Log.d(tag, message) } | ||
} | ||
} |
20 changes: 20 additions & 0 deletions
20
android-tests/src/main/kotlin/com/svenjacobs/reveal/android/tests/MainActivity.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,20 @@ | ||
package com.svenjacobs.reveal.android.tests | ||
|
||
import android.os.Bundle | ||
import androidx.activity.ComponentActivity | ||
import androidx.activity.compose.setContent | ||
import androidx.core.view.WindowCompat | ||
import com.svenjacobs.reveal.android.tests.presentation.App | ||
|
||
class MainActivity : ComponentActivity() { | ||
|
||
override fun onCreate(savedInstanceState: Bundle?) { | ||
super.onCreate(savedInstanceState) | ||
|
||
WindowCompat.setDecorFitsSystemWindows(window, false) | ||
|
||
setContent { | ||
App() | ||
} | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
android-tests/src/main/kotlin/com/svenjacobs/reveal/android/tests/presentation/App.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.android.tests.presentation | ||
|
||
import androidx.compose.runtime.Composable | ||
import androidx.compose.ui.Modifier | ||
import com.svenjacobs.reveal.RevealCanvas | ||
import com.svenjacobs.reveal.android.tests.presentation.theme.AppTheme | ||
import com.svenjacobs.reveal.rememberRevealCanvasState | ||
|
||
@Composable | ||
fun App(modifier: Modifier = Modifier) { | ||
AppTheme { | ||
val revealCanvasState = rememberRevealCanvasState() | ||
|
||
RevealCanvas( | ||
revealCanvasState = revealCanvasState, | ||
modifier = modifier, | ||
) { | ||
MainScreen(revealCanvasState = revealCanvasState) | ||
} | ||
} | ||
} |
145 changes: 145 additions & 0 deletions
145
android-tests/src/main/kotlin/com/svenjacobs/reveal/android/tests/presentation/MainScreen.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,145 @@ | ||
package com.svenjacobs.reveal.android.tests.presentation | ||
|
||
import androidx.compose.foundation.layout.Column | ||
import androidx.compose.foundation.layout.fillMaxSize | ||
import androidx.compose.foundation.layout.padding | ||
import androidx.compose.material.icons.Icons | ||
import androidx.compose.material.icons.filled.Add | ||
import androidx.compose.material3.CenterAlignedTopAppBar | ||
import androidx.compose.material3.ExperimentalMaterial3Api | ||
import androidx.compose.material3.FloatingActionButton | ||
import androidx.compose.material3.Icon | ||
import androidx.compose.material3.MaterialTheme | ||
import androidx.compose.material3.Scaffold | ||
import androidx.compose.material3.Text | ||
import androidx.compose.runtime.Composable | ||
import androidx.compose.runtime.LaunchedEffect | ||
import androidx.compose.runtime.rememberCoroutineScope | ||
import androidx.compose.ui.Alignment | ||
import androidx.compose.ui.Modifier | ||
import androidx.compose.ui.text.style.TextAlign | ||
import androidx.compose.ui.unit.dp | ||
import com.svenjacobs.reveal.Key | ||
import com.svenjacobs.reveal.Reveal | ||
import com.svenjacobs.reveal.RevealCanvasState | ||
import com.svenjacobs.reveal.RevealOverlayArrangement | ||
import com.svenjacobs.reveal.RevealOverlayScope | ||
import com.svenjacobs.reveal.RevealShape | ||
import com.svenjacobs.reveal.rememberRevealState | ||
import com.svenjacobs.reveal.shapes.balloon.Arrow | ||
import com.svenjacobs.reveal.shapes.balloon.Balloon | ||
import kotlin.time.Duration.Companion.seconds | ||
import kotlinx.coroutines.delay | ||
import kotlinx.coroutines.launch | ||
|
||
private enum class Keys { Fab, Explanation } | ||
|
||
@Composable | ||
@OptIn(ExperimentalMaterial3Api::class) | ||
fun MainScreen(revealCanvasState: RevealCanvasState, modifier: Modifier = Modifier) { | ||
val scope = rememberCoroutineScope() | ||
val revealState = rememberRevealState() | ||
|
||
LaunchedEffect(Unit) { | ||
if (revealState.isVisible) return@LaunchedEffect | ||
delay(2.seconds) | ||
revealState.reveal(Keys.Fab) | ||
} | ||
|
||
Reveal( | ||
onOverlayClick = { scope.launch { revealState.hide() } }, | ||
modifier = modifier, | ||
revealCanvasState = revealCanvasState, | ||
revealState = revealState, | ||
overlayContent = { key -> RevealOverlayContent(key) }, | ||
) { | ||
Scaffold( | ||
modifier = Modifier.fillMaxSize(), | ||
topBar = { | ||
CenterAlignedTopAppBar( | ||
title = { Text("Reveal Demo") }, | ||
) | ||
}, | ||
floatingActionButton = { | ||
FloatingActionButton( | ||
modifier = Modifier.revealable( | ||
key = Keys.Fab, | ||
shape = RevealShape.RoundRect(16.dp), | ||
onClick = { | ||
scope.launch { revealState.reveal(Keys.Explanation) } | ||
}, | ||
), | ||
onClick = { | ||
scope.launch { revealState.reveal(Keys.Explanation) } | ||
}, | ||
) { | ||
Icon( | ||
Icons.Filled.Add, | ||
contentDescription = null, | ||
) | ||
} | ||
}, | ||
) { contentPadding -> | ||
Column( | ||
modifier = Modifier | ||
.fillMaxSize() | ||
.padding(contentPadding) | ||
.padding(horizontal = 16.dp), | ||
horizontalAlignment = Alignment.CenterHorizontally, | ||
) { | ||
Text( | ||
modifier = Modifier | ||
.padding(top = 16.dp) | ||
.revealable( | ||
key = Keys.Explanation, | ||
onClick = { | ||
scope.launch { revealState.hide() } | ||
}, | ||
), | ||
text = "Reveal is a lightweight, simple reveal effect (also known as " + | ||
"coach mark or onboarding) library for Compose Multiplatform.", | ||
style = MaterialTheme.typography.bodyLarge, | ||
textAlign = TextAlign.Justify, | ||
) | ||
} | ||
} | ||
} | ||
} | ||
|
||
@Composable | ||
private fun RevealOverlayScope.RevealOverlayContent(key: Key) { | ||
when (key) { | ||
Keys.Fab -> OverlayText( | ||
modifier = Modifier.align( | ||
horizontalArrangement = RevealOverlayArrangement.Start, | ||
), | ||
text = "Click button to get started", | ||
arrow = Arrow.end(), | ||
) | ||
|
||
Keys.Explanation -> OverlayText( | ||
modifier = Modifier.align( | ||
verticalArrangement = RevealOverlayArrangement.Bottom, | ||
), | ||
text = "Actually we already started. This was an example of the reveal effect.", | ||
arrow = Arrow.top(), | ||
) | ||
} | ||
} | ||
|
||
@Composable | ||
private fun OverlayText(text: String, arrow: Arrow, modifier: Modifier = Modifier) { | ||
Balloon( | ||
modifier = modifier.padding(8.dp), | ||
arrow = arrow, | ||
backgroundColor = MaterialTheme.colorScheme.secondaryContainer, | ||
elevation = 2.dp, | ||
) { | ||
Text( | ||
modifier = Modifier.padding(8.dp), | ||
text = text, | ||
style = MaterialTheme.typography.labelLarge, | ||
textAlign = TextAlign.Center, | ||
) | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
...oid-tests/src/main/kotlin/com/svenjacobs/reveal/android/tests/presentation/theme/Theme.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,11 @@ | ||
package com.svenjacobs.reveal.android.tests.presentation.theme | ||
|
||
import androidx.compose.material3.MaterialTheme | ||
import androidx.compose.runtime.Composable | ||
|
||
@Composable | ||
fun AppTheme(content: @Composable () -> Unit) { | ||
MaterialTheme( | ||
content = content, | ||
) | ||
} |
Empty file.
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,8 @@ | ||
<resources xmlns:tools="http://schemas.android.com/tools"> | ||
|
||
<style name="AppTheme" parent="android:Theme.Material.Light.NoActionBar"> | ||
<item name="android:statusBarColor">@android:color/transparent</item> | ||
<item name="android:navigationBarColor">@android:color/transparent</item> | ||
<item name="android:windowLightStatusBar" tools:targetApi="m">true</item> | ||
</style> | ||
</resources> |
18 changes: 18 additions & 0 deletions
18
reveal-common/src/commonMain/kotlin/com/svenjacobs/reveal/common/internal/log/Logger.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,18 @@ | ||
package com.svenjacobs.reveal.common.internal.log | ||
|
||
/** | ||
* Minimal logging adapter for development purposes. | ||
* For internal use only. | ||
*/ | ||
public object Logger { | ||
|
||
public fun interface Adapter { | ||
public fun d(message: String, tag: String) | ||
} | ||
|
||
public var adapter: Adapter? = null | ||
|
||
public fun d(message: String, tag: String = "Reveal") { | ||
adapter?.d(message, tag) | ||
} | ||
} |
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