Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TF2 floating cursor #1598

Draft
wants to merge 1 commit into
base: jb-main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,21 @@
package androidx.compose.foundation.text.input.internal

import androidx.compose.foundation.content.internal.ReceiveContentConfiguration
import androidx.compose.runtime.snapshotFlow
import androidx.compose.ui.ExperimentalComposeUiApi
import androidx.compose.ui.platform.PlatformTextInputMethodRequest
import androidx.compose.ui.platform.PlatformTextInputSession
import androidx.compose.ui.platform.ViewConfiguration
import androidx.compose.ui.text.TextLayoutResult
import androidx.compose.ui.text.input.EditCommand
import androidx.compose.ui.text.input.EditProcessor
import androidx.compose.ui.text.input.ImeAction
import androidx.compose.ui.text.input.ImeOptions
import androidx.compose.ui.text.input.TextFieldValue
import kotlinx.coroutines.coroutineScope
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.MutableSharedFlow
import kotlinx.coroutines.flow.filterNotNull
import kotlinx.coroutines.launch

@OptIn(ExperimentalComposeUiApi::class)
Expand Down Expand Up @@ -86,6 +90,7 @@ internal actual suspend fun PlatformTextInputSession.platformSpecificTextInputSe
state.visualText.selection,
state.visualText.composition,
),
textLayoutResult = snapshotFlow(layoutState::layoutResult).filterNotNull(),
imeOptions = imeOptions,
onEditCommand = ::onEditCommand,
onImeAction = onImeAction,
Expand All @@ -101,5 +106,6 @@ private data class SkikoPlatformTextInputMethodRequest(
override val imeOptions: ImeOptions,
override val onEditCommand: (List<EditCommand>) -> Unit,
override val onImeAction: ((ImeAction) -> Unit)?,
override val editProcessor: EditProcessor?
override val editProcessor: EditProcessor?,
override val textLayoutResult: Flow<TextLayoutResult>
): PlatformTextInputMethodRequest
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,13 @@
package androidx.compose.ui.platform

import androidx.compose.ui.ExperimentalComposeUiApi
import androidx.compose.ui.text.TextLayoutResult
import androidx.compose.ui.text.input.EditCommand
import androidx.compose.ui.text.input.EditProcessor
import androidx.compose.ui.text.input.ImeAction
import androidx.compose.ui.text.input.ImeOptions
import androidx.compose.ui.text.input.TextFieldValue
import kotlinx.coroutines.flow.Flow

actual interface PlatformTextInputMethodRequest {
@ExperimentalComposeUiApi
Expand All @@ -34,4 +36,6 @@ actual interface PlatformTextInputMethodRequest {
val onImeAction: ((ImeAction) -> Unit)?
@ExperimentalComposeUiApi
val editProcessor: EditProcessor?
@ExperimentalComposeUiApi
val textLayoutResult : Flow<TextLayoutResult>
}
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,10 @@ internal class UIKitTextInputService(
innerTextFieldBounds,
decorationBoxBounds
)
updateTextLayoutResult(textLayoutResult)
}

fun updateTextLayoutResult(textLayoutResult: TextLayoutResult) {
this.textLayoutResult = textLayoutResult
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.setValue
import androidx.compose.runtime.snapshotFlow
import androidx.compose.ui.Modifier
import androidx.compose.ui.SessionMutex
import androidx.compose.ui.draganddrop.UIKitDragAndDropManager
Expand Down Expand Up @@ -101,6 +102,9 @@ import kotlinx.cinterop.CValue
import kotlinx.cinterop.readValue
import kotlinx.cinterop.useContents
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.awaitCancellation
import kotlinx.coroutines.coroutineScope
import kotlinx.coroutines.launch
import kotlinx.coroutines.suspendCancellableCoroutine
import platform.CoreGraphics.CGAffineTransformIdentity
import platform.CoreGraphics.CGAffineTransformInvert
Expand Down Expand Up @@ -709,17 +713,24 @@ internal class ComposeSceneMediator(
innerSessionMutex.withSessionCancellingPrevious(
sessionInitializer = { null }
) {
suspendCancellableCoroutine<Nothing> { continuation ->
textInputService.startInput(
value = request.state,
imeOptions = request.imeOptions,
editProcessor = request.editProcessor,
onEditCommand = request.onEditCommand,
onImeActionPerformed = request.onImeAction ?: {}
)

continuation.invokeOnCancellation {
textInputService.stopInput()
coroutineScope {
launch {
request.textLayoutResult.collect {
textInputService.updateTextLayoutResult(it)
}
}
suspendCancellableCoroutine<Nothing> { continuation ->
textInputService.startInput(
value = request.state,
imeOptions = request.imeOptions,
editProcessor = request.editProcessor,
onEditCommand = request.onEditCommand,
onImeActionPerformed = request.onImeAction ?: {}
)

continuation.invokeOnCancellation {
textInputService.stopInput()
}
}
}
}
Expand Down