Clément Cardonnel
07/28/2022, 10:17 AM@Composable
fun ParkView(parkId: String, viewModel: ParkViewModel = ParkViewModel(context = LocalContext.current, parkId = parkId)) {}
But when there’s a change inside my composable, I think it gets recomposed and alongside it my view model is recreated. For example, I have a TabRow which updates the view model when its onClick lambda is triggered.
viewModel.tabIndex.value = index
This triggers an infinite loop, where my viewModel is recreated indefinitely.
Where the view model should be instantiated or at least, how can I avoid this infinite loop? I’m providing an example of view and its viewModel in the replies.
And of course, thank you very much for your answers 😌Albert Chang
07/28/2022, 11:24 AMModifier.height().wrapContentHeight(align = <http://Alignment.Top|Alignment.Top>)
Android75
07/28/2022, 1:03 PMkotlinOptions.jvmTarget = "11"
buildFeatures {
compose = true
}
composeOptions {
kotlinCompilerExtensionVersion = "1.3.0-rc01"
}
"androidx.compose.ui:ui:1.2.0"
"androidx.compose.material:material:1.2.0"
"androidx.compose.ui:ui-tooling-preview:1.2.0"
"androidx.activity:activity-compose"1.3.1"
here my actiivy
class MyActivityCompose : ComponentActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContent {
Greeting("Android")
}
}
}
@Composable
fun Greeting(name: String) {
Text(text = "Hello $name!")
}
ad i have this error
java.lang.NoSuchMethodError: No static method setContent$default(Landroidx/activity/ComponentActivity;Landroidx/compose/runtime/CompositionContext;Lkotlin/jvm/functions/Function0;ILjava/lang/Object;)V in class Landroidx/activity/compose/ComponentActivityKt; or its super classes (declaration of ‘androidx.activity.compose.ComponentActivityKt’ appears in /data/app/~~Ft9dSkXEHEzaK6HUxVW0Mw==/com.xxx.xxx.preprod-G6wAmGkpV4l7HVqxZrBhrg==/base.apk)Tgo1014
07/28/2022, 1:14 PMBottomAppBarDefaults.FloatingActionButton
which was added in material3:1.0.0-alpha14
but it's gone in alpha15
with no mentions in the changelog. Does anyone knows why?Lisandro Di Meo
07/28/2022, 2:31 PMLisandro Di Meo
07/28/2022, 2:32 PMdeviant
07/28/2022, 2:34 PMjacksonfdam
07/28/2022, 2:48 PMjava.lang.NoClassDefFoundError: Failed resolution of: Landroidx/test/platform/graphics/HardwareRendererCompat;
at androidx.compose.ui.test.android.WindowCapture_androidKt.withDrawingEnabled(WindowCapture.android.kt:55)
at androidx.compose.ui.test.android.WindowCapture_androidKt.captureRegionToImage(WindowCapture.android.kt:46)
at androidx.compose.ui.test.AndroidImageHelpers_androidKt.processSingleWindowScreenshot(AndroidImageHelpers.android.kt:138)
at androidx.compose.ui.test.AndroidImageHelpers_androidKt.captureToImage(AndroidImageHelpers.android.kt:75)
at androidx.compose.ui.test.AndroidImageHelpers_androidKt.captureToImage(AndroidImageHelpers.android.kt:50)
and...
Caused by: java.lang.ClassNotFoundException: Didn't find class "androidx.test.platform.graphics.HardwareRendererCompat" on path: DexPathList[[zip file "/system/framework/android.test.runner.jar", zip file "/system/framework/android.test.mock.jar", zip file "/system/framework/android.test.base.jar",
Everything that invokes the captureToImage
crashes
fun SemanticsNodeInteraction.assertBackgroundColor2(color: Color) {
val capturedName = captureToImage().colorSpace.name
assertEquals(color.colorSpace.name, capturedName)
}
I'm using Kotlin 1.6.21 with the latest stable versions of the following libs
androidTestImplementation TestDependencies.composeTooling
androidTestImplementation Compose.test
androidTestImplementation Compose.uiTest
androidTestImplementation TestDependencies.hamcrest
androidTestImplementation TestDependencies.espressoCore
androidTestImplementation TestDependencies.espressoContrib
androidTestImplementation TestDependencies.archCore
androidTestImplementation TestDependencies.coreTest
androidTestImplementation TestDependencies.truth
androidTestImplementation TestDependencies.androidJunit
androidTestImplementation TestDependencies.androidJunitKtx
androidTestImplementation TestDependencies.androidxTestOrchestrator
androidTestImplementation TestDependencies.androidxTestRunner
androidTestImplementation TestDependencies.androidxTestRules
androidTestImplementation TestDependencies.androidxTestMonitor
androidTestUtil TestDependencies.androidxTestOrchestrator
Maybe I missed something.. or not... any suggestions?Adam Powell
07/28/2022, 3:05 PMandrew
07/28/2022, 6:26 PMorangy
07/28/2022, 8:08 PMArrangement
that would do what you need. It’s not hard. This looks like justified
arrangement I wrote recently. It’s not perfect for RTL/LTR and maybe something else, but it could give you an idea
fun Arrangement.justified(minSpace: Dp): Arrangement.HorizontalOrVertical = object : Arrangement.HorizontalOrVertical {
override val spacing: Dp
get() = minSpace
override fun Density.arrange(totalSize: Int, sizes: IntArray, layoutDirection: LayoutDirection, outPositions: IntArray) {
if (sizes.isEmpty()) return
val minSpacePx = minSpace.roundToPx()
val measuredSize = sizes.sum()
val spacePx = if (sizes.size > 1)
kotlin.math.max((totalSize - measuredSize) / (sizes.size - 1), minSpacePx)
else
minSpacePx
var occupied = 0
var lastSpace = 0
val reversed = layoutDirection == LayoutDirection.Rtl
sizes.forEachIndexed(reversed) { index, it ->
outPositions[index] = kotlin.math.min(occupied, totalSize - it)
lastSpace = kotlin.math.min(spacePx, totalSize - outPositions[index] - it)
occupied = outPositions[index] + it + lastSpace
}
}
override fun Density.arrange(totalSize: Int, sizes: IntArray, outPositions: IntArray) =
arrange(totalSize, sizes, LayoutDirection.Ltr, outPositions)
override fun toString() = "Arrangement#justified($minSpace)"
}
martmists
07/28/2022, 11:38 PMmartmists
07/28/2022, 11:50 PM> Task :jsBrowserDevelopmentRun FAILED
[webpack-cli] TypeError: cli.isMultipleCompiler is not a function
[webpack-cli] TypeError: cli.isMultipleCompiler is not a function
at Command.<anonymous> (/home/mart/git/bloks/build/js/node_modules/@webpack-cli/serve/lib/index.js:146:35)
at async Promise.all (index 1)
at async Command.<anonymous> (/home/mart/git/bloks/build/js/node_modules/webpack-cli/lib/webpack-cli.js:1687:7)
brabo-hi
07/29/2022, 12:10 AMTin Tran
07/29/2022, 2:54 AMonTextLayout
callback but it’s only for single text. What should I do to sync the reduced text size to all the elements in a LazyColumn
if 1 of the elements has overflown text size?Colton Idle
07/29/2022, 4:29 AMdrawText
extension function on DrawScope
to provide a way to draw multi-styled text on composables and modifiers that operate on a DrawScope
like Canvas
and drawBehind
.
• Soft keyboard will now be hidden when a text field is disabled while focused.
• When adding InputEventChange
events to Velocity Tracker we will consider now deltas instead of positions, this will guarantee the velocity is correctly calculated for all cases even if the target element moves
• When a scrollable has a focused child, it will now correctly scroll to keep the focused child in view when its size is decreased, even when the size is animated.
• Fixed a crash where TextField
is cleared and refilled while selection is active.
• Fix AnimatedVisibility
issue with FloatingActionButton
in Scaffold
• Re-added ComposerKt.traceEventStart(Int, String)
for backwards compatibility (I wonder if this is related to the compose roadmap item "Composition Tracing")
• Added a new property PointerInputChange#pressure
to retrieve the pressure.
• Added rememberTextMeasurer
to easily create and remember TextMeasurer
instances in composition.
• Added drawText
extension function on DrawScope
to provide a way to draw multi-styled text on composables and modifiers that operate on a DrawScope
like Canvas
and drawBehind
.
• Introduce a new experimental API called TextMeasurer
that enables arbitrary text layout computation that creates identical results to BasicText
, independent from Compose runtime.
• Add mapTree
to SlotTree.kt
. This allows tools to inspect the SlotTree
without making an in memory copy first like asTree does. For the Layout Inspector this gives a performance improvement of about a factor 10.
• Changed Compose Preview to be stored in binary output files, in order to allow developers to write and reuse MultiPreview
annotations from libraries.
• Bunch of M3 stuff https://developer.android.com/jetpack/androidx/releases/compose-material3#1.0.0-alpha15Can Korkmaz
07/29/2022, 7:26 AMMichal Klimczak
07/29/2022, 9:26 AMYair Gadiel
07/29/2022, 9:44 AMSlackbot
07/29/2022, 10:40 AMKyant
07/29/2022, 11:19 AMMutableState
in the init
function of ViewModel
?Colton Idle
07/29/2022, 11:45 AMKotlinLeaner
07/29/2022, 1:57 PMColumn(
modifier = Modifier
.fillMaxSize(),
) {
val options = getOptions()
options.forEachIndexed { _, optionText ->
Card(
shape = RoundedCornerShape(4.dp),
) {
Text(
modifier = Modifier
.fillMaxWidth()
.background(OffWhite)
.padding(16.dp),
text = optionText,
style = Typography.h3,
fontWeight = FontWeight.Medium,
color = Slate
)
}
}
}
KotlinLeaner
07/29/2022, 2:29 PMkotlinforandroid
07/29/2022, 4:25 PMSlackbot
07/29/2022, 4:34 PMJhonatan Sabadi
07/29/2022, 4:58 PMandroid:windowSoftInputMode="adjustResize"
But the result is worst… Keyboard breaks the list.agrosner
07/29/2022, 5:28 PMFile /Users/**/.gradle/caches/transforms-3/2572c187839b7a83427c4c26c6426e28/transformed/jetified-**-5.4.0/res/font-v26/**.xml does not exist (or is not a file)
This is a depdendency resource file, using the cache. but it actually does exist.
is this some file access limitation in AS for Mac?Manojna Chintapalli
07/29/2022, 6:02 PMfloatingActionButton =
{
if (!viewModel.isReadOnly()....) {
FloatingActionButton(viewModel = viewModel, ...)
}
}
shikasd
07/30/2022, 12:32 AMshikasd
07/30/2022, 12:32 AMandrew
07/30/2022, 4:38 AM