Skip to content

gaiuszzang/GroovinExpandableBox

Repository files navigation

GroovinExpandableBox

Maven Central

This library offers a Box Composable that can be expanded/reduced through up/down swipe gestures.

MusicPlayer Sample Article Page Sample
MusicPlayerSample ArticlePageSample
Map Sample Calendar Sample
MapSample CalendarSample

Including in your project

Gradle

And add a dependency code to your module's build.gradle file.

dependencies {
    implementation 'io.groovin:expandablebox:x.x.x'
}

Usage

ExpandableBox

ExpandableBox is Expandable Layout based on Box through up/down swipe gestures.

ExpandableBox(
    modifier = modifier,
    expandableBoxState = rememberExpandableBoxState(initialValue = ExpandableBoxStateValue.Fold),
    swipeDirection = ExpandableBoxSwipeDirection.SwipeUpToExpand,
    foldHeight = 100.dp,
    halfExpandHeight = 300.dp,
    expandHeight = Dp.Unspecified,
    swipeGestureEnabled = true,
    nestedScrollEnabled = true,
    newAnchorsWithAnimated = true
) {
    Content(...)   //Contents Composable
}

Key arguments are listed below.

  • expandableBoxState : ExpandableBox needs ExpandableBoxState for store and use its status. See the section below for details.
  • swipeDirection : You can set the Swipe direction for expanding this. default = SwipeUpToExpand
  • 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 allow seamless swipe gesture with scrollable composable like Column or LazyColumn. default = true
  • newAnchorsWithAnimated : When the box anchors change, animate to the new offset instead of snapping immediately. default = true

ExpandableBoxState

ExpandableBox needs ExpandableBoxState instance for store and use its status.

val expandableBoxState = rememberExpandableBoxState(initialValue = ExpandableBoxStateValue.Fold)

Only one of the values below must be set as the initial value.

  • ExpandableBoxStateValue.Fold : Begin with Minimized state.
  • ExpandableBoxStateValue.HalfExpand : Begin with Half Expanded state. Note that halfExpandHeight must be different from foldHeight to use this.
  • ExpandableBoxStateValue.Expand : Begin with Fully Expanded state.

ExpandableBoxState exposes following parameters.

  • completedValue : Indicates that latest completion State : Fold, HalfExpand, Expand
  • progressValue : Indicates that current Progress State : Fold, Folding, HalfExpand, Expanding, Expand
  • offset : Indicates the current height offset in pixels. Note that Folding and HalfExpand States are only available when Half Expand state is used.

ExpandableBoxScope

A ExpandableBoxScope provides a scope with attributes for the content of ExpandableBox.

  • progress: Float : Progress value(0 ~ 1f) between Fold to Expand(in use Half Expand state case, Fold to HalfExpand, or HalfExpand to Expand).
  • completedState: ExpandableBoxStateValue : It is same with ExpandableBoxState.completedValue
  • progressState: ExpandableBoxStateValue : It is same with ExpandableBoxState.progressValue

also, ExpandableBoxScope inheriting BoxScope, it can be used the same as BoxScope.

License

Copyright 2023 gaiuszzang (Mincheol Shin)

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

   http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

About

Expandable/Foldable Box Library for Jetpack Compose

Topics

Resources

Stars

Watchers

Forks

Packages

 
 
 

Contributors

Languages