GithubHelp home page GithubHelp logo

cardstack's Introduction

CardStack

A hobby project of mine needed Jetpack Compose Cards stacked on top of another. As I finished up the code, I decided to polish and release it as a library so here it is.

Usage

You can define a composable and create as many cards as you want by giving a card count.

val drawables = listOf(R.drawable.first, R.drawable.second, R.drawable.third, R.drawable.fourth)

CardStack(
    { index ->
        Image(
            painterResource(id = drawables[index]),
            contentDescription = "Same Card Type with Different Image",
            contentScale = ContentScale.Crop,
            modifier = Modifier.size(196.dp, 196.dp)
        )
    },
    cardCount = drawables.size
)

Alt Text

You can also define list of composables and create different card layouts.

CardStack(
    listOf(
        {
            Text(
                text = "First Card",
                textAlign = TextAlign.Center,
                modifier = Modifier.size(196.dp)
            )
        },
        {
            Image(
                painterResource(id = R.drawable.second),
                contentDescription = "Second Card Image",
                contentScale = ContentScale.Crop,
                modifier = Modifier.size(196.dp)
            )
        },
        {
            Column(
                horizontalAlignment = Alignment.CenterHorizontally,
                modifier = Modifier.size(196.dp)
            ) {
                Text(
                    text = "Third Card With Button",
                    textAlign = TextAlign.Center
                )
                Button(onClick = {}) { Text(text = "Button Text") }
            }
        },
        {
            Image(
                painterResource(id = R.drawable.fourth),
                contentDescription = "Fourth Card Image",
                contentScale = ContentScale.Crop,
                modifier = Modifier.size(196.dp)
            )
        })
)

Alt Text

Customization

You can define;

  • Card shape
  • Card border
  • Card elevation
  • Padding between cards
  • Animation duration
  • Orientation
CardStack(
	..,
	cardCount = drawables.size,
	cardShape = CircleShape,
	cardBorder = BorderStroke(2.dp, Color.White),
	cardElevation = 10.dp,
	paddingBetweenCards = 10.dp,
	animationDuration = 250,
	orientation = Orientation.Horizontal(
	    alignment = HorizontalAlignment.EndToStart,
	    animationStyle = HorizontalAnimationStyle.FromBottom
	)
)

Alt Text

Get the Library


allprojects {
	repositories {
		maven { url 'https://jitpack.io' }
	}
}
	

implementation 'com.github.omercemcicekli:CardStack:0.0.6'
	

License


The MIT License (MIT)
	
Copyright (c) 2022 Omer Cem Cicekli
	
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
	
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
	
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
	

cardstack's People

Contributors

omercemcicekli avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

cardstack's Issues

Add max visible back stack

I am using cardstack as a gallery viewer of sorts. When there is a large number of cards in the backstack, it would be nice to have the option to limit to a specific number of visible cards, for appearances, as well as not having the composable in memory

Later cards get smaller when list is large enough

Once you get past 3/4 cards the size of later cards gets smaller and smaller.
Here is an example I did the orientation horizontal because its even more noticeable but happens with both orientations.

     val images = remember {
            mutableStateListOf(
                "https://mangadex.org/covers/a96676e5-8ae2-425e-b549-7f15dd34a6d8/dfcaab7a-2c3c-4ea5-8641-abffd2a95b5f.jpg",
                "https://mangadex.org/covers/a96676e5-8ae2-425e-b549-7f15dd34a6d8/512496fb-6e57-483f-9380-aa6027d4f157.jpg",
                "https://mangadex.org/covers/a96676e5-8ae2-425e-b549-7f15dd34a6d8/d9497f0d-3bd7-42d9-832c-696ff39a6a28.jpg",
                 "https://mangadex.org/covers/a96676e5-8ae2-425e-b549-7f15dd34a6d8/bb38cabc-769b-4b6c-b7c1-dc3a933cd3c9.jpg",
                 "https://mangadex.org/covers/a96676e5-8ae2-425e-b549-7f15dd34a6d8/e393ec1a-320d-4ef7-92de-ca84b0d20309.jpg",
                 "https://mangadex.org/covers/a96676e5-8ae2-425e-b549-7f15dd34a6d8/17acc2b0-2cab-46f2-954d-91b1174db67e.jpg",
                 "https://mangadex.org/covers/a96676e5-8ae2-425e-b549-7f15dd34a6d8/5a2e4c1d-696e-4983-ad9c-67eba37c0daa.jpg",
                 "https://mangadex.org/covers/a96676e5-8ae2-425e-b549-7f15dd34a6d8/1b266184-eb7a-4801-9ad6-8f53ac8acb47.jpg",
                 "https://mangadex.org/covers/a96676e5-8ae2-425e-b549-7f15dd34a6d8/67cc4435-16cc-4d32-8163-a82a681b826e.jpg",
                 "https://mangadex.org/covers/a96676e5-8ae2-425e-b549-7f15dd34a6d8/8b4b0dec-d3f9-4471-be67-46ea386164a1.jpg",
                 
            )
        }
Box(
            modifier = Modifier
                .fillMaxWidth()
                .fillMaxHeight(),
        ) {
            CardStack(
                cardContent = {
                    AsyncImage(
                        model = ImageRequest.Builder(LocalContext.current)
                            .data(images[it])
                            .build(),
                        contentDescription = null,
                        contentScale = ContentScale.Fit,
                        modifier = Modifier.clip(
                            RoundedCornerShape(Shapes.coverRadius),
                        ),
                    )
                },
                cardCount = images.size,
                cardShape = RoundedCornerShape(Shapes.coverRadius),
                cardElevation = 4.dp,
                paddingBetweenCards = 4.dp,
                orientation = Orientation.Horizontal(alignment = HorizontalAlignment.StartToEnd, animationStyle = HorizontalAnimationStyle.FromTop),
            )
}

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.