https://kotlinlang.org
Join Slack
Is there a way to have early-return behavior in composables from sub-functions without using excepti...
c

CLOVIS

about 3 years ago
Is there a way to have early-return behavior in composables from sub-functions without using exceptions? In standard Kotlin, we can use exceptions for early return:
// this is not idiomatic, just an extremely simplified example
fun foo(bar: String): Int {
    val int = bar.toIntOrNull()
    requireNotNull(int) { "Early return here" }
    return int
}
Using Arrow, the
either
comprehension enables similar features:
fun foo(bar: String): Either<String, Int> {
    val int = bar.toIntOrNull()
    ensureNotNull(int) { "Early return here" }
    return int
}
Using Flows, similar behavior can be emulated using
catch
:
fun foo(bar: Stirng): Flow<Result> = flow {
    val int = bar.toIntOrNull()
    requireNotNull(int) { "Early return here" }
    emit(Result.success(int))
}.catch {
    if (it !is IllegalArgumentException) throw it

    emit(Result.failure(it))
}
Which brings it to my question: what is the equivalent with
@Composable
functions?
➕ 1
c
z
p
  • 3
  • 16
  • 490
Hello, is there any way to disable swipe gestures for HorizontalPager. i want to manage the swipe ma...
h

Hachemi Hamadi

about 4 years ago
Hello, is there any way to disable swipe gestures for HorizontalPager. i want to manage the swipe manually via the pager state.
h
c
  • 2
  • 1
  • 490
Is it possible to get IntelliJ to list unused imports in the whole project? I've got `Settings -&gt;...
k

Klitos Kyriacou

about 4 years ago
Is it possible to get IntelliJ to list unused imports in the whole project? I've got
Settings -> Inspections -> Kotlin -> Unused import directive
set to "Warning", but when I build the project I don't see any unused imports listed. I can only see them by going to individual files in the editor and looking for greyed-out import statements. When looking at Java projects, on the other hand, I can see a list of used imports when I build.
k
m
  • 2
  • 1
  • 490
Is there a way to dynamically modify tables? Instead of adding a new column in the table definition,...
j

JP

about 5 years ago
Is there a way to dynamically modify tables? Instead of adding a new column in the table definition, can I do something like
transaction{
   Table.addColumn(...)
}
?
j
r
  • 2
  • 6
  • 490
How to resolve this issue Unresolved reference: Res ```Res.drawable.ic_facebook``` Unresolved refere...
c

CRUD Mehra

over 1 year ago
How to resolve this issue Unresolved reference: Res
Res.drawable.ic_facebook
Unresolved reference: <projectName>.composeapp.generated.resources.*
c
y
+2
  • 4
  • 21
  • 489
In my compose desktop application, I want the user to start voice input with the space key. However ...
s

Sebastian Lehrbaum

almost 2 years ago
In my compose desktop application, I want the user to start voice input with the space key. However I obviously don't want that to happen if the user is in a textfield, as they may be using the space key as part of their text input. I expected text fields to consume the key event, however I still get the event on the window even when a textfield is selected (it also adds the space in the texfield). Any idea how to avoid it?
Window(
    ...
	onKeyEvent = { keyEvent ->
		if (keyEvent.key == Key.Spacebar && keyEvent.type == KeyEventType.KeyDown) {
			println("Got space") // happens even when a textfield consumes the key event first
			true
		} else {
			false
		}
	}
)
s
s
+5
  • 7
  • 36
  • 488
I know AutoSizing/Shrinking Text is on the Compose roadmap, but it's not clear when that will actual...
t

Travis Griggs

almost 2 years ago
I know AutoSizing/Shrinking Text is on the Compose roadmap, but it's not clear when that will actually happen. I've seen some gists that iteratively make use of Text's
onTextLayout
closure. But I was asking myself, why not just use a Canvas rather than a Text if I'm just after simplified single line Text drawing, and want to specify a "minimum font size". Curious why this would be a bad idea? Or if I'm missing obvious things? Code on thread
t
k
+4
  • 6
  • 18
  • 488
hello everyone. how are you handling one-time events between the viewmodel and compose? snackbars a...
a

André Tessmer

over 2 years ago
hello everyone. how are you handling one-time events between the viewmodel and compose? snackbars and navigation for example
a
m
+6
  • 8
  • 32
  • 488
Can this With | old Native GC, variable in singleton without @ThreadLocal can't be changed after ini...
i

itnoles

over 2 years ago
Can this With | old Native GC, variable in singleton without @ThreadLocal can't be changed after initialization | warning be ignored in Kotlin 1.8.10?
i
l
  • 2
  • 3
  • 488
I’m getting a report in crashlytics with this stacktrace. Crashlytics points `kotlin::FormatToSpan(k...
j

jean

over 3 years ago
I’m getting a report in crashlytics with this stacktrace. Crashlytics points
kotlin::FormatToSpan(kotlin::std_support::span<char, 18446744073709551615ul>, char const*, ...) + 4354272500
to be the culprit. I have no Idea how to find what causes this, how should I proceed?
Untitled.txt
j
m
m
  • 3
  • 4
  • 488
Previous134135136Next

kotlinlang

A modern programming language that makes developers happier.

Powered by