Skip to content

Commit

Permalink
Merge pull request #6 from gaiuszzang/release/v1.2.4
Browse files Browse the repository at this point in the history
Release/v1.2.4
  • Loading branch information
gaiuszzang authored Jul 19, 2024
2 parents 408e1fe + 1166ae3 commit c2c92e3
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 15 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ There are 6 arguments to be aware of use.
- `foldHeight` : Define the Minimized Height. `Mandatory`
- `halfExpandHeight` : Define the Half Expanded Height If you want to use Half Expanded State. If not defined, half expanded state is not used. `Optional`
- `expandHeight` : Define the Fully Expanded Height. The default is `Dp.Unspecified`, which sets it to the parent's maximum height. `Optional`
- `swipeGestureEnabled` : You can disable swipe gesture. `default = true`
- `nestedScrollEnabled` : You can enable nested scrolling to allowing seamless swipe gesture with scrollable composable like Column or LazyColumn. `default = true`


Expand Down
6 changes: 3 additions & 3 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@
buildscript {
ext {
androidx_core_version = '1.13.1'
compose_bom_version = '2024.04.00'
compose_bom_version = '2024.06.00'
compose_compiler_version = '1.5.8'
kotlin_plugin_version = '1.9.22'
}
}

plugins {
id 'com.android.application' version '8.1.0' apply false
id 'com.android.library' version '8.1.0' apply false
id 'com.android.application' version '8.1.4' apply false
id 'com.android.library' version '8.1.4' apply false
id 'org.jetbrains.kotlin.android' version "$kotlin_plugin_version" apply false
}
2 changes: 1 addition & 1 deletion expandablebox/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ afterEvaluate {
from components.release
groupId = 'io.groovin'
artifactId = 'groovinexpandablebox'
version = '1.2.3'
version = '1.2.4'
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ import androidx.compose.ui.input.nestedscroll.nestedScroll
import androidx.compose.ui.platform.LocalDensity
import androidx.compose.ui.unit.Dp
import androidx.compose.ui.unit.Velocity
import kotlin.math.round


@Composable
fun ExpandableBox(
Expand All @@ -24,6 +26,7 @@ fun ExpandableBox(
foldHeight: Dp,
halfExpandHeight: Dp = foldHeight,
expandHeight: Dp = Dp.Unspecified,
swipeGestureEnabled: Boolean = true,
nestedScrollEnabled: Boolean = true,
content: @Composable ExpandableBoxScope.() -> Unit
) {
Expand Down Expand Up @@ -87,15 +90,15 @@ fun ExpandableBox(
.expandableBoxSwipeable(
state = expandableBoxState,
anchors = anchors,
enabled = foldHeightPx > 0 || expandableBoxState.completedValue != ExpandableBoxStateValue.Fold,
enabled = swipeGestureEnabled && foldHeightPx > 0 || expandableBoxState.completedValue != ExpandableBoxStateValue.Fold,
orientation = Orientation.Vertical,
reverseDirection = isDownDirection,
thresholds = { _, _ -> FractionalThreshold(0.7f) },
resistance = ExpandableBoxSwipeableDefaults.resistanceConfig(anchors.keys, 0f, 0f) //Prevent moving animation when over swiping
)
.nestedScroll(nestedScrollConnection)
) {
val innerHeightDp = with(density) { (expandableBoxState.offset.value).toDp() }
val innerHeightDp = with(density) { (expandableBoxState.correctedOffset).toDp() }
Box(
modifier = Modifier
.fillMaxWidth()
Expand All @@ -105,13 +108,13 @@ fun ExpandableBox(
val progressState = expandableBoxState.progressValue
val progress = if (progressState == ExpandableBoxStateValue.Fold || progressState == ExpandableBoxStateValue.Folding) {
if (halfExpandHeightPx != 0f) {
(expandableBoxState.offset.value / (halfExpandHeightPx)).coerceIn(0f, 1f)
(expandableBoxState.correctedOffset / (halfExpandHeightPx)).coerceIn(0f, 1f)
} else {
1f
}
} else {
if (expandHeightPx != halfExpandHeightPx) {
((expandableBoxState.offset.value - halfExpandHeightPx) / (expandHeightPx - halfExpandHeightPx)).coerceIn(0f, 1f)
((expandableBoxState.correctedOffset - halfExpandHeightPx) / (expandHeightPx - halfExpandHeightPx)).coerceIn(0f, 1f)
} else {
1f
}
Expand All @@ -128,19 +131,23 @@ fun ExpandableBox(
}

private fun ExpandableBoxState.updateProgressState(foldHeightPx: Float, halfExpandHeightPx: Float, expandHeightPx: Float) {
val stateOffset = correctedOffset
progressValue = if (foldHeightPx == halfExpandHeightPx) {
when {
offset.value <= foldHeightPx -> ExpandableBoxStateValue.Fold
offset.value > foldHeightPx && offset.value < expandHeightPx -> ExpandableBoxStateValue.Expanding
stateOffset <= foldHeightPx -> ExpandableBoxStateValue.Fold
stateOffset > foldHeightPx && stateOffset < expandHeightPx -> ExpandableBoxStateValue.Expanding
else -> ExpandableBoxStateValue.Expand
}
} else {
when {
offset.value <= foldHeightPx -> ExpandableBoxStateValue.Fold
offset.value < halfExpandHeightPx -> ExpandableBoxStateValue.Folding
offset.value == halfExpandHeightPx -> ExpandableBoxStateValue.HalfExpand
offset.value > halfExpandHeightPx && offset.value < expandHeightPx -> ExpandableBoxStateValue.Expanding
stateOffset <= foldHeightPx -> ExpandableBoxStateValue.Fold
stateOffset < halfExpandHeightPx -> ExpandableBoxStateValue.Folding
stateOffset == halfExpandHeightPx -> ExpandableBoxStateValue.HalfExpand
stateOffset > halfExpandHeightPx && stateOffset < expandHeightPx -> ExpandableBoxStateValue.Expanding
else -> ExpandableBoxStateValue.Expand
}
}
}

private val ExpandableBoxState.correctedOffset: Float
get() = round(offset.value * 1000) / 1000
2 changes: 1 addition & 1 deletion sampleapp/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ dependencies {
debugImplementation "androidx.compose.ui:ui-tooling"

//Lifecycle
def lifecycle_version = '2.8.1'
def lifecycle_version = '2.8.2'
implementation "androidx.lifecycle:lifecycle-runtime-ktx:$lifecycle_version"
implementation "androidx.lifecycle:lifecycle-viewmodel-ktx:$lifecycle_version"
implementation "androidx.lifecycle:lifecycle-viewmodel-compose:$lifecycle_version"
Expand Down

0 comments on commit c2c92e3

Please sign in to comment.