Skip to content

Commit 6b2c535

Browse files
committed
state added and version change.
1 parent 5be3e2a commit 6b2c535

File tree

4 files changed

+34
-27
lines changed

4 files changed

+34
-27
lines changed

app/build.gradle

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,10 @@ android {
4848

4949
dependencies {
5050

51+
ext {
52+
accompanist_version = '0.26.5-rc'
53+
}
54+
5155
implementation 'androidx.core:core-ktx:1.7.0'
5256
implementation "androidx.compose.ui:ui:$compose_ui_version"
5357
implementation "androidx.compose:compose-compiler:1.0.0-alpha03"
@@ -63,7 +67,8 @@ dependencies {
6367

6468
implementation "io.coil-kt:coil-compose:2.1.0"
6569

66-
implementation "com.google.accompanist:accompanist-systemuicontroller:0.24.9-beta"
70+
implementation "com.google.accompanist:accompanist-systemuicontroller:$accompanist_version"
71+
implementation "com.google.accompanist:accompanist-pager:$accompanist_version"
6772

6873
// implementation 'com.github.commandiron:ExpandableHorizontalPagerCompose:1.0.0'
6974
implementation project(':expandable-horizontal-pager')

app/src/main/java/com/commandiron/expandablehorizontalpagercompose/MainActivity.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,12 @@ import coil.request.ImageRequest
2828
import com.commandiron.expandable_horizontal_pager.ExpandableHorizontalPager
2929
import com.commandiron.expandablehorizontalpagercompose.Film.Companion.films
3030
import com.commandiron.expandablehorizontalpagercompose.ui.theme.ExpandableHorizontalPagerComposeTheme
31+
import com.google.accompanist.pager.ExperimentalPagerApi
3132
import com.google.accompanist.systemuicontroller.rememberSystemUiController
3233

3334
class MainActivity : ComponentActivity() {
3435

36+
@OptIn(ExperimentalPagerApi::class)
3537
override fun onCreate(savedInstanceState: Bundle?) {
3638
super.onCreate(savedInstanceState)
3739
WindowCompat.setDecorFitsSystemWindows(window, false)

expandable-horizontal-pager/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ afterEvaluate {
5757

5858
groupId = 'com.github.commandiron'
5959
artifactId = 'expandable-horizontal-pager'
60-
version = '1.0.3'
60+
version = '1.0.4'
6161
}
6262
}
6363
}

expandable-horizontal-pager/src/main/java/com/commandiron/expandable_horizontal_pager/ExpandableHorizontalPager.kt

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -22,16 +22,15 @@ import androidx.compose.ui.graphics.graphicsLayer
2222
import androidx.compose.ui.unit.Dp
2323
import androidx.compose.ui.unit.dp
2424
import androidx.compose.ui.util.lerp
25-
import com.google.accompanist.pager.ExperimentalPagerApi
26-
import com.google.accompanist.pager.HorizontalPager
27-
import com.google.accompanist.pager.calculateCurrentOffsetForPage
25+
import com.google.accompanist.pager.*
2826
import kotlin.math.absoluteValue
2927

3028
@OptIn(ExperimentalPagerApi::class)
3129
@Composable
3230
fun ExpandableHorizontalPager(
3331
count: Int,
3432
modifier: Modifier = Modifier,
33+
state: PagerState = rememberPagerState(),
3534
reverseLayout: Boolean = false,
3635
itemSpacing: Dp = 0.dp,
3736
initialHorizontalPadding: Dp = 0.dp,
@@ -52,15 +51,15 @@ fun ExpandableHorizontalPager(
5251
hiddenContentBoxHeight: Dp = Dp.Unspecified,
5352
hiddenContent: @Composable ColumnScope.(page: Int) -> Unit
5453
) {
55-
var state by rememberSaveable { mutableStateOf(ExpandablePagerState.INITIAL) }
54+
var transformState by rememberSaveable { mutableStateOf(ExpandablePagerTransformState.INITIAL) }
5655

57-
fun setStateOnAnimationFinish(expandablePagerState: ExpandablePagerState) {
58-
when (expandablePagerState) {
59-
ExpandablePagerState.INITIAL_TO_TARGET -> {
60-
state = ExpandablePagerState.TARGET
56+
fun setStateOnAnimationFinish(expandablePagerTransformState: ExpandablePagerTransformState) {
57+
when (expandablePagerTransformState) {
58+
ExpandablePagerTransformState.INITIAL_TO_TARGET -> {
59+
transformState = ExpandablePagerTransformState.TARGET
6160
}
62-
ExpandablePagerState.TARGET_TO_INITIAL -> {
63-
state = ExpandablePagerState.INITIAL
61+
ExpandablePagerTransformState.TARGET_TO_INITIAL -> {
62+
transformState = ExpandablePagerTransformState.INITIAL
6463
}
6564
else -> {}
6665
}
@@ -89,7 +88,7 @@ fun ExpandableHorizontalPager(
8988
durationMillis = durationMillis
9089
),
9190
finishedListener = {
92-
setStateOnAnimationFinish(state)
91+
setStateOnAnimationFinish(transformState)
9392
}
9493
)
9594

@@ -109,7 +108,7 @@ fun ExpandableHorizontalPager(
109108
durationMillis = durationMillis
110109
),
111110
finishedListener = {
112-
setStateOnAnimationFinish(state)
111+
setStateOnAnimationFinish(transformState)
113112
}
114113
)
115114

@@ -130,9 +129,9 @@ fun ExpandableHorizontalPager(
130129
)
131130

132131
fun expand(maxHeight: Dp) {
133-
if(state == ExpandablePagerState.INITIAL) {
132+
if(transformState == ExpandablePagerTransformState.INITIAL) {
134133

135-
state = ExpandablePagerState.INITIAL_TO_TARGET
134+
transformState = ExpandablePagerTransformState.INITIAL_TO_TARGET
136135

137136
horizontalPaddingState = targetHorizontalPadding
138137

@@ -152,9 +151,9 @@ fun ExpandableHorizontalPager(
152151
}
153152

154153
cornerSizeState = 0.dp
155-
} else if (state == ExpandablePagerState.TARGET) {
154+
} else if (transformState == ExpandablePagerTransformState.TARGET) {
156155

157-
state = ExpandablePagerState.TARGET_TO_INITIAL
156+
transformState = ExpandablePagerTransformState.TARGET_TO_INITIAL
158157

159158
horizontalPaddingState = initialHorizontalPadding
160159

@@ -171,6 +170,7 @@ fun ExpandableHorizontalPager(
171170
HorizontalPager(
172171
count = count,
173172
modifier = modifier,
173+
state = state,
174174
reverseLayout = reverseLayout,
175175
itemSpacing = itemSpacing,
176176
contentPadding = PaddingValues(horizontal = horizontalPadding),
@@ -189,7 +189,7 @@ fun ExpandableHorizontalPager(
189189
if (currentPage == page) {
190190
boxHeight
191191
} else {
192-
if(state == ExpandablePagerState.TARGET) boxHeight else 0.dp
192+
if (transformState == ExpandablePagerTransformState.TARGET) boxHeight else 0.dp
193193
}
194194
)
195195
.offset(
@@ -198,7 +198,7 @@ fun ExpandableHorizontalPager(
198198
)
199199
.graphicsLayer {
200200
val pageOffset = calculateCurrentOffsetForPage(page).absoluteValue
201-
if (state != ExpandablePagerState.TARGET) {
201+
if (transformState != ExpandablePagerTransformState.TARGET) {
202202
if (outerItemScaleEnabled) {
203203
lerp(
204204
start = outerItemScale,
@@ -234,7 +234,7 @@ fun ExpandableHorizontalPager(
234234
contentAlignment = Alignment.Center
235235
) {
236236
Column() {
237-
if(state == ExpandablePagerState.TARGET) {
237+
if(transformState == ExpandablePagerTransformState.TARGET) {
238238
hiddenContent(page)
239239
}
240240
}
@@ -251,7 +251,7 @@ fun ExpandableHorizontalPager(
251251
)
252252
.graphicsLayer {
253253
val pageOffset = calculateCurrentOffsetForPage(page).absoluteValue
254-
if (state != ExpandablePagerState.TARGET) {
254+
if (transformState != ExpandablePagerTransformState.TARGET) {
255255
if (outerItemScaleEnabled) {
256256
lerp(
257257
start = outerItemScale,
@@ -292,8 +292,8 @@ fun ExpandableHorizontalPager(
292292
}
293293
Column() {
294294
AnimatedVisibility(
295-
visible = state == ExpandablePagerState.INITIAL ||
296-
state == ExpandablePagerState.TARGET_TO_INITIAL,
295+
visible = transformState == ExpandablePagerTransformState.INITIAL ||
296+
transformState == ExpandablePagerTransformState.TARGET_TO_INITIAL,
297297
enter = fadeIn(tween(durationMillis)),
298298
exit = fadeOut(tween(durationMillis))
299299
) {
@@ -302,8 +302,8 @@ fun ExpandableHorizontalPager(
302302
}
303303
Column() {
304304
AnimatedVisibility(
305-
visible = state == ExpandablePagerState.TARGET ||
306-
state == ExpandablePagerState.INITIAL_TO_TARGET,
305+
visible = transformState == ExpandablePagerTransformState.TARGET ||
306+
transformState == ExpandablePagerTransformState.INITIAL_TO_TARGET,
307307
enter = fadeIn(tween(durationMillis)),
308308
exit = fadeOut(tween(durationMillis))
309309
) {
@@ -316,6 +316,6 @@ fun ExpandableHorizontalPager(
316316
}
317317
}
318318

319-
enum class ExpandablePagerState {
319+
enum class ExpandablePagerTransformState {
320320
INITIAL, INITIAL_TO_TARGET, TARGET_TO_INITIAL, TARGET
321321
}

0 commit comments

Comments
 (0)