-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Include 2 news Composables and more extensions
- Loading branch information
Showing
13 changed files
with
230 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
<vector xmlns:android="http://schemas.android.com/apk/res/android" | ||
android:width="28dp" | ||
android:height="28dp" | ||
android:viewportWidth="28" | ||
android:viewportHeight="28"> | ||
<path | ||
android:fillColor="#212121" | ||
android:pathData="M14.6036,6.1928C17.205,3.2606 21.7875,3.2705 24.3762,6.2139C26.6389,8.7867 26.5238,12.6719 24.1126,15.1062L14.5327,24.7778C14.3919,24.92 14.2001,25 13.9999,25C13.7998,25 13.6079,24.92 13.4671,24.7778L3.8873,15.106C1.4763,12.6718 1.3611,8.7868 3.6237,6.214C6.2124,3.2706 10.7949,3.2606 13.3963,6.1928L13.9999,6.8732L14.6036,6.1928Z" /> | ||
</vector> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 23 additions & 0 deletions
23
...n/java/com/jeluchu/jchucomponentscompose/core/extensions/activities/ActivityExtensions.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package com.jeluchu.jchucomponentscompose.core.extensions.activities | ||
|
||
import android.Manifest | ||
import android.app.Activity | ||
import android.content.pm.PackageManager | ||
import androidx.core.app.ActivityCompat | ||
|
||
|
||
private val permissionsList = | ||
arrayOf(Manifest.permission.WRITE_EXTERNAL_STORAGE, Manifest.permission.READ_EXTERNAL_STORAGE) | ||
|
||
val Activity.permissions: Unit | ||
get() { | ||
val perm = | ||
ActivityCompat.checkSelfPermission(this, Manifest.permission.WRITE_EXTERNAL_STORAGE) | ||
if (perm != PackageManager.PERMISSION_GRANTED) { | ||
ActivityCompat.requestPermissions( | ||
this, | ||
permissionsList, | ||
1 | ||
) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 6 additions & 0 deletions
6
...se/src/main/java/com/jeluchu/jchucomponentscompose/core/extensions/file/FileExtensions.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
package com.jeluchu.jchucomponentscompose.core.extensions.file | ||
|
||
import java.io.File | ||
|
||
val File.extension: String | ||
get() = name.substringAfterLast('.', "") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 23 additions & 0 deletions
23
.../src/main/java/com/jeluchu/jchucomponentscompose/core/extensions/lists/ListsExtensions.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package com.jeluchu.jchucomponentscompose.core.extensions.lists | ||
|
||
import androidx.compose.foundation.MutatePriority | ||
import androidx.compose.foundation.lazy.LazyListState | ||
import kotlinx.coroutines.CoroutineScope | ||
import kotlinx.coroutines.awaitCancellation | ||
import kotlinx.coroutines.launch | ||
|
||
/** Await indefinitely, blocking scrolls **/ | ||
fun LazyListState.disableScrolling(scope: CoroutineScope) { | ||
scope.launch { | ||
scroll(scrollPriority = MutatePriority.PreventUserInput) { | ||
awaitCancellation() | ||
} | ||
} | ||
} | ||
|
||
/** Cancel the previous indefinite "scroll" blocking **/ | ||
fun LazyListState.reenableScrolling(scope: CoroutineScope) { | ||
scope.launch { | ||
scroll(scrollPriority = MutatePriority.PreventUserInput) {} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
86 changes: 86 additions & 0 deletions
86
...tscompose/src/main/java/com/jeluchu/jchucomponentscompose/ui/images/DoubleTapAnimation.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
package com.jeluchu.jchucomponentscompose.ui.images | ||
|
||
import androidx.compose.animation.core.Spring | ||
import androidx.compose.animation.core.animateDpAsState | ||
import androidx.compose.animation.core.spring | ||
import androidx.compose.foundation.Image | ||
import androidx.compose.foundation.gestures.detectTapGestures | ||
import androidx.compose.foundation.layout.Box | ||
import androidx.compose.foundation.layout.fillMaxSize | ||
import androidx.compose.foundation.layout.size | ||
import androidx.compose.material.Icon | ||
import androidx.compose.runtime.* | ||
import androidx.compose.ui.Alignment | ||
import androidx.compose.ui.Modifier | ||
import androidx.compose.ui.graphics.Color | ||
import androidx.compose.ui.input.pointer.pointerInput | ||
import androidx.compose.ui.res.painterResource | ||
import androidx.compose.ui.unit.Dp | ||
import androidx.compose.ui.unit.dp | ||
import com.jeluchu.jchucomponentscompose.core.extensions.ints.empty | ||
import com.jeluchu.jchucomponentscompose.core.extensions.strings.empty | ||
|
||
@Composable | ||
fun DoubleTapAnimation( | ||
imageRemote: String = String.empty(), | ||
imageResources: Int = Int.empty(), | ||
iconResource: Int, | ||
size: Dp = 250.dp, | ||
onDoubleTap: () -> Unit | ||
) { | ||
var isLike by remember { mutableStateOf(false) } | ||
val animatedSize by animateDpAsState( | ||
targetValue = if (isLike) size else 0.dp, | ||
animationSpec = spring( | ||
dampingRatio = Spring.DampingRatioMediumBouncy, | ||
stiffness = 500f | ||
) | ||
) | ||
Box(modifier = Modifier.fillMaxSize()) { | ||
|
||
if (imageRemote.isNotEmpty()) { | ||
NetworkImage( | ||
url = imageRemote, | ||
modifier = Modifier | ||
.align(Alignment.Center) | ||
.pointerInput(Unit) { | ||
detectTapGestures( | ||
onDoubleTap = { | ||
isLike = true | ||
onDoubleTap() | ||
} | ||
) | ||
} | ||
) | ||
} else { | ||
Image( | ||
painter = painterResource(id = imageResources), | ||
contentDescription = String.empty(), | ||
modifier = Modifier | ||
.align(Alignment.Center) | ||
.pointerInput(Unit) { | ||
detectTapGestures( | ||
onDoubleTap = { | ||
isLike = true | ||
onDoubleTap() | ||
} | ||
) | ||
}) | ||
} | ||
|
||
|
||
if (isLike) { | ||
Icon( | ||
painterResource(id = iconResource), | ||
tint = Color.White, | ||
modifier = Modifier | ||
.size(animatedSize) | ||
.align(Alignment.Center), | ||
contentDescription = "" | ||
) | ||
if (animatedSize == size) { | ||
isLike = false | ||
} | ||
} | ||
} | ||
} |
55 changes: 55 additions & 0 deletions
55
...ponentscompose/src/main/java/com/jeluchu/jchucomponentscompose/ui/loaders/PulseLoading.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
package com.jeluchu.jchucomponentscompose.ui.loaders | ||
|
||
import androidx.compose.animation.core.* | ||
import androidx.compose.foundation.layout.Box | ||
import androidx.compose.foundation.layout.fillMaxSize | ||
import androidx.compose.foundation.layout.size | ||
import androidx.compose.foundation.shape.CircleShape | ||
import androidx.compose.material.Card | ||
import androidx.compose.runtime.Composable | ||
import androidx.compose.runtime.getValue | ||
import androidx.compose.ui.Alignment | ||
import androidx.compose.ui.Modifier | ||
import androidx.compose.ui.draw.alpha | ||
import androidx.compose.ui.graphics.Color | ||
import androidx.compose.ui.unit.dp | ||
|
||
@Composable | ||
fun PulseLoading( | ||
durationMillis:Int = 1000, | ||
maxPulseSize:Float = 300f, | ||
minPulseSize:Float = 50f, | ||
pulseColor: Color = Color(234,240,246), | ||
centreColor:Color = Color(66,133,244) | ||
){ | ||
val infiniteTransition = rememberInfiniteTransition() | ||
val size by infiniteTransition.animateFloat( | ||
initialValue = minPulseSize, | ||
targetValue = maxPulseSize, | ||
animationSpec = infiniteRepeatable( | ||
animation = tween(durationMillis, easing = LinearEasing), | ||
repeatMode = RepeatMode.Restart | ||
) | ||
) | ||
val alpha by infiniteTransition.animateFloat( | ||
initialValue = 1f, | ||
targetValue = 0f, | ||
animationSpec = infiniteRepeatable( | ||
animation = tween(durationMillis, easing = LinearEasing), | ||
repeatMode = RepeatMode.Restart | ||
) | ||
) | ||
Box(contentAlignment = Alignment.Center,modifier = Modifier.fillMaxSize()) { | ||
Card( | ||
shape = CircleShape, | ||
modifier = Modifier.size(size.dp).align(Alignment.Center).alpha(alpha), | ||
backgroundColor = pulseColor, | ||
elevation = 0.dp | ||
) {} | ||
Card(modifier = Modifier | ||
.size(minPulseSize.dp) | ||
.align(Alignment.Center), | ||
shape = CircleShape, | ||
backgroundColor = centreColor){} | ||
} | ||
} |