Skip to content

Commit aa09857

Browse files
authored
Merge pull request #23 from tahaak67/develop
v1.1.1 release
2 parents 2f39345 + 6885c92 commit aa09857

3 files changed

Lines changed: 37 additions & 22 deletions

File tree

showcase-layout-compose/build.gradle.kts

Lines changed: 3 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
import org.jetbrains.kotlin.gradle.targets.js.webpack.KotlinWebpackConfig
2-
31
plugins {
42
alias(libs.plugins.kotlinMultiplatform)
53
alias(libs.plugins.androidLibrary)
@@ -19,19 +17,8 @@ kotlin {
1917

2018
@OptIn(org.jetbrains.kotlin.gradle.ExperimentalWasmDsl::class)
2119
wasmJs {
22-
outputModuleName = "composeApp"
23-
browser {
24-
commonWebpackConfig {
25-
outputFileName = "composeApp.js"
26-
devServer = (devServer ?: KotlinWebpackConfig.DevServer()).apply {
27-
static = (static ?: mutableListOf()).apply {
28-
// Serve sources to debug inside browser
29-
add(project.projectDir.path)
30-
}
31-
}
32-
}
33-
}
34-
binaries.executable()
20+
outputModuleName = "showcase-layout-compose"
21+
browser()
3522
}
3623

3724

@@ -70,7 +57,7 @@ mavenPublishing {
7057
publishToMavenCentral()
7158
signAllPublications()
7259

73-
coordinates("ly.com.tahaben", "showcase-layout-compose", "1.1.0")
60+
coordinates("ly.com.tahaben", "showcase-layout-compose", "1.1.1")
7461

7562
pom {
7663
name.set("Showcase Layout Compose")

showcase-layout-compose/src/commonMain/kotlin/ly/com/tahaben/showcase_layout_compose/ui/ShowcaseLayout.kt

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import androidx.compose.ui.graphics.StrokeCap
1919
import androidx.compose.ui.graphics.drawscope.Stroke
2020
import androidx.compose.ui.graphics.drawscope.rotate
2121
import androidx.compose.ui.input.pointer.pointerInput
22+
import androidx.compose.ui.layout.LayoutCoordinates
2223
import androidx.compose.ui.layout.onGloballyPositioned
2324
import androidx.compose.ui.layout.positionInRoot
2425
import androidx.compose.ui.platform.LocalDensity
@@ -97,7 +98,9 @@ fun ShowcaseLayout(
9798
}
9899
val currentContent by rememberUpdatedState(content)
99100
val resetDelay by derivedStateOf { animationDuration.toLong() + INDEX_RESET_DELAY }
101+
val layoutCoordinatesState = remember { mutableStateOf<LayoutCoordinates?>(null) }
100102
val scope = ShowcaseScopeImpl(greeting)
103+
scope.layoutCoordinatesState = layoutCoordinatesState
101104
scope.currentContent()
102105

103106
var singleGreetingMsg by remember { mutableStateOf<ShowcaseMsg?>(null) }
@@ -133,7 +136,10 @@ fun ShowcaseLayout(
133136
}
134137
}
135138

136-
BoxWithConstraints(modifier = Modifier.fillMaxSize()) {
139+
BoxWithConstraints(modifier = Modifier
140+
.fillMaxSize()
141+
.onGloballyPositioned { layoutCoordinatesState.value = it }
142+
) {
137143
val coroutineScope = rememberCoroutineScope()
138144
if (isShowcasing || showCasingItem || isSingleGreeting) {
139145
val offset by animateOffsetAsState(
@@ -1014,6 +1020,10 @@ fun ShowcaseLayout(
10141020

10151021
class ShowcaseScopeImpl(greeting: ShowcaseMsg?) : ShowcaseScope {
10161022
private val showcaseDataHashMap = HashMap<Int, ShowcaseData>()
1023+
1024+
/** Coordinates of the showcase layout itself, used to convert target positions from
1025+
* root space to the layout's local space (the space the overlay canvas draws in). */
1026+
internal var layoutCoordinatesState: State<LayoutCoordinates?> = mutableStateOf(null)
10171027
override var showcaseEventListener: ShowcaseEventListener? = null
10181028
private val _showcaseActionFlow = MutableStateFlow<Int?>(null)
10191029
val showcaseActionFlow = _showcaseActionFlow.asStateFlow()
@@ -1108,11 +1118,22 @@ class ShowcaseScopeImpl(greeting: ShowcaseMsg?) : ShowcaseScope {
11081118
}
11091119

11101120
fun getPositionFor(index: Int): Offset {
1111-
if (index == 0) {
1112-
return showcaseDataHashMap[1]?.position ?: Offset(0f, 0f)
1121+
val data = showcaseDataHashMap[if (index == 0) 1 else index] ?: return Offset(0f, 0f)
1122+
return positionInLayout(data)
1123+
}
1124+
1125+
/** The stored position is relative to the composition root, but the overlay canvas draws
1126+
* in the layout's local space. When the layout doesn't sit at the root origin (status bar
1127+
* padding, app bars, ...) the two spaces differ, so convert; the raw root position is only
1128+
* a fallback for when either set of coordinates is detached. */
1129+
private fun positionInLayout(data: ShowcaseData): Offset {
1130+
val layoutCoordinates = layoutCoordinatesState.value
1131+
val targetCoordinates = data.coordinates
1132+
return if (layoutCoordinates?.isAttached == true && targetCoordinates?.isAttached == true) {
1133+
layoutCoordinates.localPositionOf(targetCoordinates, Offset.Zero)
1134+
} else {
1135+
data.position
11131136
}
1114-
val p = showcaseDataHashMap[index]?.position ?: Offset(0f, 0f)
1115-
return p
11161137
}
11171138

11181139
fun getHashMapSize(): Int {

showcase-layout-compose/src/commonMain/kotlin/ly/com/tahaben/showcase_layout_compose/ui/TargetShowcaseLayout.kt

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ import androidx.compose.ui.graphics.Path
1414
import androidx.compose.ui.graphics.PathOperation
1515
import androidx.compose.ui.graphics.drawscope.Fill
1616
import androidx.compose.ui.input.pointer.pointerInput
17+
import androidx.compose.ui.layout.LayoutCoordinates
18+
import androidx.compose.ui.layout.onGloballyPositioned
1719
import androidx.compose.ui.platform.LocalDensity
1820
import androidx.compose.ui.semantics.semantics
1921
import androidx.compose.ui.semantics.testTag
@@ -93,7 +95,9 @@ fun TargetShowcaseLayout(
9395
mutableIntStateOf(validatedInitIndex)
9496
}
9597
val currentContent by rememberUpdatedState(content)
98+
val layoutCoordinatesState = remember { mutableStateOf<LayoutCoordinates?>(null) }
9699
val scope = ShowcaseScopeImpl(greeting)
100+
scope.layoutCoordinatesState = layoutCoordinatesState
97101
scope.currentContent()
98102
val localDensity = LocalDensity.current
99103
var singleGreetingMsg by remember { mutableStateOf<ShowcaseMsg?>(null) }
@@ -128,7 +132,10 @@ fun TargetShowcaseLayout(
128132
}
129133
}
130134

131-
BoxWithConstraints(modifier = Modifier.fillMaxSize()) {
135+
BoxWithConstraints(modifier = Modifier
136+
.fillMaxSize()
137+
.onGloballyPositioned { layoutCoordinatesState.value = it }
138+
) {
132139
val coroutineScope = rememberCoroutineScope()
133140
if (isShowcasing || showCasingItem || isSingleGreeting) {
134141
var itemSize = scope.getSizeFor(currentIndex)

0 commit comments

Comments
 (0)