Skip to content

Commit

Permalink
Merge pull request #72 from ltttttttttttt/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
ltttttttttttt authored Nov 2, 2023
2 parents 1bfaaa3 + 1161004 commit 263603d
Show file tree
Hide file tree
Showing 12 changed files with 371 additions and 582 deletions.
4 changes: 2 additions & 2 deletions ComposeViews/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ plugins {
group = "io.github.ltttttttttttt"
//上传到mavenCentral命令: ./gradlew publishAllPublicationsToSonatypeRepository
//mavenCentral后台: https://s01.oss.sonatype.org/#stagingRepositories
version = "$composeVersion.5"
version = "$composeVersion.1"

kotlin {
androidTarget {
Expand Down Expand Up @@ -152,5 +152,5 @@ android {

//compose配置
compose {
kotlinCompilerPlugin.set("androidx.compose.compiler:compiler:$composeCompilerVersion")
//kotlinCompilerPlugin.set("androidx.compose.compiler:compiler:$composeCompilerVersion")
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ import com.lt.compose_views.chain_scrollable_component.ChainScrollableComponent
import com.lt.compose_views.chain_scrollable_component.ChainScrollableComponentState
import com.lt.compose_views.chain_scrollable_component.mode.ChainMode
import com.lt.compose_views.util.ComposePosition
import com.lt.compose_views.util.applyIf
import kotlinx.coroutines.launch
import kotlin.math.abs
import kotlin.math.roundToInt
Expand Down Expand Up @@ -94,16 +95,13 @@ fun SwipeToDismiss(
Row(
modifier = Modifier
.matchParentSize()
.let {
if (contentIsMove) {
it.offset {
IntOffset(
(state.getScrollPositionValue() - state.maxPx).roundToInt(),
0
)
}
} else
it
.applyIf(contentIsMove) {
offset {
IntOffset(
(state.getScrollPositionValue() - state.maxPx).roundToInt(),
0
)
}
}
.horizontalScroll(scrollState)
) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import androidx.compose.ui.layout.Layout
import androidx.compose.ui.platform.LocalDensity
import androidx.compose.ui.unit.Dp
import androidx.compose.ui.unit.dp
import com.lt.compose_views.util.applyIf
import com.lt.compose_views.util.midOf
import com.lt.compose_views.util.rememberMutableStateOf
import kotlinx.coroutines.flow.Flow
Expand Down Expand Up @@ -94,11 +95,8 @@ fun PagerIndicator(
val offsetPercentWithSelect by offsetPercentWithSelectFlow.collectAsState(0f)
val selectIndex by selectIndexFlow.collectAsState(0)

Layout(modifier = modifier.let {
if (userCanScroll) {
it.scrollable(scrollState, orientation)
} else
it
Layout(modifier = modifier.applyIf(userCanScroll) {
scrollable(scrollState, orientation)
}, content = {
pagerIndicatorScope.selectIndicatorItem()
repeat(size) {
Expand Down Expand Up @@ -335,11 +333,8 @@ fun PagerIndicator(
}
}

Layout(modifier = modifier.let {
if (userCanScroll) {
it.scrollable(scrollState, orientation)
} else
it
Layout(modifier = modifier.applyIf(userCanScroll) {
scrollable(scrollState, orientation)
}, content = {
pagerIndicatorScope.selectIndicatorItem()
repeat(size) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import com.lt.compose_views.util.ComposePosition.Bottom
import com.lt.compose_views.util.ComposePosition.End
import com.lt.compose_views.util.ComposePosition.Start
import com.lt.compose_views.util.ComposePosition.Top
import com.lt.compose_views.util.applyIf
import kotlin.math.roundToInt

/**
Expand Down Expand Up @@ -120,11 +121,8 @@ fun RefreshLayout(
refreshLayoutState.refreshContent()
},
modifier = modifier
.let {
if (userEnable)
it.nestedScroll(nestedScrollState)
else
it
.applyIf(userEnable) {
nestedScroll(nestedScrollState)
}
.clipScrollableContainer(composePosition.orientation)
) { measurableList, constraints ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,18 @@ import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.size
import androidx.compose.runtime.*
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.rememberUpdatedState
import androidx.compose.runtime.setValue
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.painter.Painter
import androidx.compose.ui.unit.Dp
import androidx.compose.ui.unit.dp
import com.lt.compose_views.res.Res
import com.lt.compose_views.util.applyIf
import kotlin.math.roundToInt

/**
Expand Down Expand Up @@ -101,14 +107,11 @@ fun StarBar(
contentDescription = "star",
modifier = Modifier
.size(starSize)
.let {
if (userEnable)
it.clickable(remember { MutableInteractionSource() }, null) {
onStarValueChange(index + 1)
onTouchUpEvent?.invoke()
}
else
it
.applyIf(userEnable) {
clickable(remember { MutableInteractionSource() }, null) {
onStarValueChange(index + 1)
onTouchUpEvent?.invoke()
}
},
)
if (index < maxStar - 1)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,10 @@

package com.lt.compose_views.util

import androidx.compose.runtime.Composable
import androidx.compose.runtime.remember
import androidx.compose.ui.graphics.Color
import kotlin.contracts.ExperimentalContracts
import kotlin.contracts.InvocationKind
import kotlin.contracts.contract

/**
* creator: lt 2022/6/27 lt.dygzs@qq.com
Expand All @@ -45,4 +46,15 @@ internal fun Float/*percentage*/.getPercentageValue(startValue: Color, endValue:
red = getPercentageValue(startValue.red, endValue.red),
green = getPercentageValue(startValue.green, endValue.green),
blue = getPercentageValue(startValue.blue, endValue.blue),
)
)

/**
* 如果[userBlock]为true则返回[block]的返回值,否则返回this
*/
@OptIn(ExperimentalContracts::class)
internal inline fun <T> T.applyIf(userBlock: Boolean, block: T.() -> T): T {
contract {
callsInPlace(block, InvocationKind.AT_MOST_ONCE)
}
return if (userBlock) block(this) else this
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import androidx.compose.ui.input.pointer.pointerInput
import androidx.compose.ui.layout.Layout
import androidx.compose.ui.unit.Constraints
import androidx.compose.ui.unit.IntOffset
import com.lt.compose_views.util.applyIf
import com.lt.compose_views.util.midOf
import kotlin.math.roundToInt

Expand Down Expand Up @@ -61,18 +62,15 @@ fun ZoomLayout(
) {
//不限制宽高,且多个控件叠加展示
Layout(content, Modifier.align(alignment)
.let {
if (userCanRotation)
it.rotate(zoomState.rotation)
else
it
}
.scale(zoomState.zoom)
.offset {
IntOffset(
zoomState.offset.x.roundToInt(),
zoomState.offset.y.roundToInt()
)
}
.applyIf(userCanRotation) {
rotate(zoomState.rotation)
}) { measurableList, constraints ->
var maxWidth = 0
var maxHeight = 0
Expand Down
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ View demo</a>

<table broder="1">
<tr><td>ComposeViews version</td><td>jetpack compose version</td><td>compose-multiplatform version</td><td>kotlin version</td></tr>
<tr><td><img src="https://img.shields.io/maven-central/v/io.github.ltttttttttttt/ComposeViews"/></td><td>1.5.0</td><td>1.5.1</td><td>1.9.0</td></tr>
<tr><td><img src="https://img.shields.io/maven-central/v/io.github.ltttttttttttt/ComposeViews"/></td><td>1.5.4</td><td>1.5.10</td><td>1.9.20</td></tr>
<tr><td>1.5.1.5</td><td>1.5.0</td><td>1.5.1</td><td>1.9.0</td></tr>
<tr><td>1.5.0.3</td><td>1.5.0</td><td>1.5.0</td><td>1.9.0</td></tr>
<tr><td>1.4.0.14</td><td>1.4.0</td><td>1.4.0</td><td>1.8.20</td></tr>
<tr><td>1.3.11</td><td>1.3.3</td><td>1.3.1</td><td>1.8.10</td></tr>
Expand Down
3 changes: 2 additions & 1 deletion README_CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@

<table broder="1">
<tr><td>ComposeViews version</td><td>jetpack compose version</td><td>compose-multiplatform version</td><td>kotlin version</td></tr>
<tr><td><img src="https://img.shields.io/maven-central/v/io.github.ltttttttttttt/ComposeViews"/></td><td>1.5.0</td><td>1.5.1</td><td>1.9.0</td></tr>
<tr><td><img src="https://img.shields.io/maven-central/v/io.github.ltttttttttttt/ComposeViews"/></td><td>1.5.4</td><td>1.5.10</td><td>1.9.20</td></tr>
<tr><td>1.5.1.5</td><td>1.5.0</td><td>1.5.1</td><td>1.9.0</td></tr>
<tr><td>1.5.0.3</td><td>1.5.0</td><td>1.5.0</td><td>1.9.0</td></tr>
<tr><td>1.4.0.14</td><td>1.4.0</td><td>1.4.0</td><td>1.8.20</td></tr>
<tr><td>1.3.11</td><td>1.3.3</td><td>1.3.1</td><td>1.8.10</td></tr>
Expand Down
2 changes: 1 addition & 1 deletion android_app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ android {
compose = true
}
composeOptions {
kotlinCompilerExtensionVersion = composeCompilerVersion
//kotlinCompilerExtensionVersion = composeCompilerVersion
}
}

Expand Down
6 changes: 3 additions & 3 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,6 @@ kotlin.mpp.androidSourceSetLayoutVersion=2
kotlin.native.binary.memoryModel=experimental

#Versions
kotlin.version=1.9.0
compose.version=1.5.1
ksp.version=1.9.0-1.0.13
kotlin.version=1.9.20
compose.version=1.5.10
ksp.version=1.9.20-1.0.13
Loading

0 comments on commit 263603d

Please sign in to comment.