Skip to content

Commit

Permalink
Move PlatformContextTextInputService to a separate file.
Browse files Browse the repository at this point in the history
  • Loading branch information
m-sasha committed Aug 18, 2024
1 parent e249584 commit 3b572cd
Show file tree
Hide file tree
Showing 3 changed files with 169 additions and 141 deletions.
4 changes: 0 additions & 4 deletions compose/ui/ui/api/desktop/ui.api
Original file line number Diff line number Diff line change
Expand Up @@ -3330,10 +3330,6 @@ public abstract interface class androidx/compose/ui/platform/PlatformContextText
public fun updateTextLayoutResult (Landroidx/compose/ui/platform/TextFieldStateAdapter;Landroidx/compose/ui/text/input/OffsetMapping;Landroidx/compose/ui/text/TextLayoutResult;Lkotlin/jvm/functions/Function1;Landroidx/compose/ui/geometry/Rect;Landroidx/compose/ui/geometry/Rect;)V
}

public final class androidx/compose/ui/platform/PlatformContext_skikoKt {
public static final fun asPlatformTextInputService (Landroidx/compose/ui/platform/PlatformContextTextInputService;)Landroidx/compose/ui/text/input/PlatformTextInputService;
}

public abstract interface class androidx/compose/ui/platform/PlatformDragAndDropManager {
public abstract fun drag-12SF9DM (Landroidx/compose/ui/draganddrop/DragAndDropTransferData;JLkotlin/jvm/functions/Function1;)Z
public abstract fun getModifier ()Landroidx/compose/ui/Modifier;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -299,140 +299,3 @@ internal class DelegateRootForTestListener : PlatformContext.RootForTestListener
}
}

/**
* Platform specific text input service.
*
* This is a non-deprecated version of [PlatformTextInputService], which is needed because we can't
* expose deprecated APIs in [PlatformContext].
*/
interface PlatformContextTextInputService {
/**
* Start text input session for given client.
*
* @see TextInputService.startInput
*/
fun startInput(
value: TextFieldStateAdapter,
imeOptions: ImeOptions,
onEditCommand: (List<EditCommand>) -> Unit,
onImeActionPerformed: ((ImeAction) -> Unit)?
)

/**
* Restart input and show the keyboard. This should only be called when starting a new
* `PlatformTextInputModifierNode.textInputSession`.
*
* @see TextInputService.startInput
*/
fun startInput() {}

/**
* Stop text input session.
*
* @see TextInputService.stopInput
*/
fun stopInput()

/**
* Request showing onscreen keyboard
*
* There is no guarantee nor callback of the result of this API.
*
* @see TextInputService.showSoftwareKeyboard
*/
fun showSoftwareKeyboard()

/**
* Hide software keyboard
*
* @see TextInputService.hideSoftwareKeyboard
*/
fun hideSoftwareKeyboard()

/**
* Notify the new editor model to IME.
*
* @see TextInputSession.updateState
*/
fun updateState(oldValue: TextFieldStateAdapter?, newValue: TextFieldStateAdapter)

/**
* Notify the focused rectangle to the system.
*
* The system can ignore this information or use it to for additional functionality.
*
* For example, desktop systems show a popup near the focused input area (for some languages).
*/
// TODO(b/262648050) Try to find a better API.
fun notifyFocusedRect(rect: Rect) {
}

/**
* Notify the input service of layout and position changes.
*
* @see TextInputSession.updateTextLayoutResult
*/
fun updateTextLayoutResult(
textFieldValue: TextFieldStateAdapter,
offsetMapping: OffsetMapping,
textLayoutResult: TextLayoutResult,
textFieldToRootTransform: (Matrix) -> Unit,
innerTextFieldBounds: Rect,
decorationBoxBounds: Rect
) {
}
}

@Suppress("DEPRECATION")
fun PlatformContextTextInputService.asPlatformTextInputService() = object : PlatformTextInputService {
override fun startInput(
value: TextFieldValue,
imeOptions: ImeOptions,
onEditCommand: (List<EditCommand>) -> Unit,
onImeActionPerformed: (ImeAction) -> Unit
) {
this@asPlatformTextInputService.startInput(
value = value.asTextFieldStateAdapter(),
imeOptions = imeOptions,
onEditCommand = onEditCommand,
onImeActionPerformed = onImeActionPerformed
)
}

override fun startInput() = this@asPlatformTextInputService.startInput()

override fun stopInput() = this@asPlatformTextInputService.stopInput()

override fun showSoftwareKeyboard() = this@asPlatformTextInputService.showSoftwareKeyboard()

override fun hideSoftwareKeyboard() = this@asPlatformTextInputService.hideSoftwareKeyboard()

override fun updateState(oldValue: TextFieldValue?, newValue: TextFieldValue) {
this@asPlatformTextInputService.updateState(
oldValue = oldValue?.asTextFieldStateAdapter(),
newValue = newValue.asTextFieldStateAdapter()
)
}

override fun notifyFocusedRect(rect: Rect) {
this@asPlatformTextInputService.notifyFocusedRect(rect)
}

override fun updateTextLayoutResult(
textFieldValue: TextFieldValue,
offsetMapping: OffsetMapping,
textLayoutResult: TextLayoutResult,
textFieldToRootTransform: (Matrix) -> Unit,
innerTextFieldBounds: Rect,
decorationBoxBounds: Rect
) {
this@asPlatformTextInputService.updateTextLayoutResult(
textFieldValue = textFieldValue.asTextFieldStateAdapter(),
offsetMapping = offsetMapping,
textLayoutResult = textLayoutResult,
textFieldToRootTransform = textFieldToRootTransform,
innerTextFieldBounds = innerTextFieldBounds,
decorationBoxBounds = decorationBoxBounds
)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,169 @@
/*
* Copyright 2024 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package androidx.compose.ui.platform

import androidx.compose.ui.geometry.Rect
import androidx.compose.ui.graphics.Matrix
import androidx.compose.ui.text.TextLayoutResult
import androidx.compose.ui.text.input.EditCommand
import androidx.compose.ui.text.input.ImeAction
import androidx.compose.ui.text.input.ImeOptions
import androidx.compose.ui.text.input.OffsetMapping
import androidx.compose.ui.text.input.PlatformTextInputService
import androidx.compose.ui.text.input.TextFieldValue
import androidx.compose.ui.text.input.TextInputService
import androidx.compose.ui.text.input.TextInputSession


/**
* Platform specific text input service.
*
* This is a non-deprecated version of [PlatformTextInputService], which is needed because we can't
* expose deprecated APIs in [PlatformContext].
*/
interface PlatformContextTextInputService {
/**
* Start text input session for given client.
*
* @see TextInputService.startInput
*/
fun startInput(
value: TextFieldStateAdapter,
imeOptions: ImeOptions,
onEditCommand: (List<EditCommand>) -> Unit,
onImeActionPerformed: ((ImeAction) -> Unit)?
)

/**
* Restart input and show the keyboard. This should only be called when starting a new
* `PlatformTextInputModifierNode.textInputSession`.
*
* @see TextInputService.startInput
*/
fun startInput() {}

/**
* Stop text input session.
*
* @see TextInputService.stopInput
*/
fun stopInput()

/**
* Request showing onscreen keyboard
*
* There is no guarantee nor callback of the result of this API.
*
* @see TextInputService.showSoftwareKeyboard
*/
fun showSoftwareKeyboard()

/**
* Hide software keyboard
*
* @see TextInputService.hideSoftwareKeyboard
*/
fun hideSoftwareKeyboard()

/**
* Notify the new editor model to IME.
*
* @see TextInputSession.updateState
*/
fun updateState(oldValue: TextFieldStateAdapter?, newValue: TextFieldStateAdapter)

/**
* Notify the focused rectangle to the system.
*
* The system can ignore this information or use it to for additional functionality.
*
* For example, desktop systems show a popup near the focused input area (for some languages).
*/
// TODO(b/262648050) Try to find a better API.
fun notifyFocusedRect(rect: Rect) {
}

/**
* Notify the input service of layout and position changes.
*
* @see TextInputSession.updateTextLayoutResult
*/
fun updateTextLayoutResult(
textFieldValue: TextFieldStateAdapter,
offsetMapping: OffsetMapping,
textLayoutResult: TextLayoutResult,
textFieldToRootTransform: (Matrix) -> Unit,
innerTextFieldBounds: Rect,
decorationBoxBounds: Rect
) {
}
}

@Suppress("DEPRECATION")
internal fun PlatformContextTextInputService.asPlatformTextInputService() = object :
PlatformTextInputService {
override fun startInput(
value: TextFieldValue,
imeOptions: ImeOptions,
onEditCommand: (List<EditCommand>) -> Unit,
onImeActionPerformed: (ImeAction) -> Unit
) {
this@asPlatformTextInputService.startInput(
value = value.asTextFieldStateAdapter(),
imeOptions = imeOptions,
onEditCommand = onEditCommand,
onImeActionPerformed = onImeActionPerformed
)
}

override fun startInput() = this@asPlatformTextInputService.startInput()

override fun stopInput() = this@asPlatformTextInputService.stopInput()

override fun showSoftwareKeyboard() = this@asPlatformTextInputService.showSoftwareKeyboard()

override fun hideSoftwareKeyboard() = this@asPlatformTextInputService.hideSoftwareKeyboard()

override fun updateState(oldValue: TextFieldValue?, newValue: TextFieldValue) {
this@asPlatformTextInputService.updateState(
oldValue = oldValue?.asTextFieldStateAdapter(),
newValue = newValue.asTextFieldStateAdapter()
)
}

override fun notifyFocusedRect(rect: Rect) {
this@asPlatformTextInputService.notifyFocusedRect(rect)
}

override fun updateTextLayoutResult(
textFieldValue: TextFieldValue,
offsetMapping: OffsetMapping,
textLayoutResult: TextLayoutResult,
textFieldToRootTransform: (Matrix) -> Unit,
innerTextFieldBounds: Rect,
decorationBoxBounds: Rect
) {
this@asPlatformTextInputService.updateTextLayoutResult(
textFieldValue = textFieldValue.asTextFieldStateAdapter(),
offsetMapping = offsetMapping,
textLayoutResult = textLayoutResult,
textFieldToRootTransform = textFieldToRootTransform,
innerTextFieldBounds = innerTextFieldBounds,
decorationBoxBounds = decorationBoxBounds
)
}
}

0 comments on commit 3b572cd

Please sign in to comment.