Browse Source

web: Remove deprecated input event listeners (#861)

Co-authored-by: Oleksandr Karpovich <oleksandr.karpovich@jetbrains.com>
pull/864/head
Oleksandr Karpovich 4 years ago committed by GitHub
parent
commit
8edc12f02a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 2
      web/benchmark-core/src/jsMain/kotlin/com/sample/content/CodeSamplesSwitcher.kt
  2. 53
      web/core/src/jsMain/kotlin/androidx/compose/web/attributes/InputAttrsBuilder.kt
  3. 13
      web/core/src/jsMain/kotlin/androidx/compose/web/attributes/TextAreaAttrsBuilder.kt
  4. 6
      web/integration-core/src/jsMain/kotlin/androidx/compose/web/sample/CodeSnippetSamples.kt
  5. 16
      web/integration-core/src/jsMain/kotlin/androidx/compose/web/sample/Sample.kt
  6. 5
      web/widgets/src/jsMain/kotlin/layouts/slider.kt

2
web/benchmark-core/src/jsMain/kotlin/com/sample/content/CodeSamplesSwitcher.kt

@ -75,7 +75,7 @@ fun CodeSampleSwitcher(count: Int, current: Int, onSelect: (Int) -> Unit) {
value("snippet$ix")
id("snippet$ix")
if (current == ix) checked()
onRadioInput { onSelect(ix) }
onInput { onSelect(ix) }
})
Label(forId = "snippet$ix") { Text("${ix + 1}") }
}

53
web/core/src/jsMain/kotlin/androidx/compose/web/attributes/InputAttrsBuilder.kt

@ -5,11 +5,9 @@
package androidx.compose.web.attributes
import org.jetbrains.compose.web.attributes.*
import org.jetbrains.compose.web.events.GenericWrappedEvent
import org.jetbrains.compose.web.events.WrappedCheckBoxInputEvent
import org.jetbrains.compose.web.events.WrappedRadioInputEvent
import org.jetbrains.compose.web.events.WrappedTextInputEvent
import org.jetbrains.compose.web.attributes.AttrsBuilder
import org.jetbrains.compose.web.attributes.InputType
import org.jetbrains.compose.web.attributes.Options
import org.w3c.dom.HTMLElement
import org.w3c.dom.HTMLInputElement
import org.w3c.dom.events.Event
@ -45,49 +43,4 @@ class InputAttrsBuilder<T>(val inputType: InputType<T>) : AttrsBuilder<HTMLInput
listener(SyntheticInputEvent(value, it.nativeEvent.target as HTMLInputElement, it.nativeEvent))
}
}
@Deprecated(
message = "It's not reliable as it can be applied to any input type.",
replaceWith = ReplaceWith("onInput(options, listener)"),
level = DeprecationLevel.WARNING
)
fun onTextInput(options: Options = Options.DEFAULT, listener: (WrappedTextInputEvent) -> Unit) {
listeners.add(TextInputEventListener(options, listener))
}
@Deprecated(
message = "It's not reliable as it can be applied to any input type.",
replaceWith = ReplaceWith("onInput(options, listener)"),
level = DeprecationLevel.WARNING
)
fun onCheckboxInput(
options: Options = Options.DEFAULT,
listener: (WrappedCheckBoxInputEvent) -> Unit
) {
listeners.add(CheckBoxInputEventListener(options, listener))
}
@Deprecated(
message = "It's not reliable as it can be applied to any input type.",
replaceWith = ReplaceWith("onInput(options, listener)"),
level = DeprecationLevel.WARNING
)
fun onRadioInput(
options: Options = Options.DEFAULT,
listener: (WrappedRadioInputEvent) -> Unit
) {
listeners.add(RadioInputEventListener(options, listener))
}
@Deprecated(
message = "It's not reliable as it can be applied to any input type.",
replaceWith = ReplaceWith("onInput(options, listener)"),
level = DeprecationLevel.WARNING
)
fun onRangeInput(
options: Options = Options.DEFAULT,
listener: (GenericWrappedEvent<*>) -> Unit
) {
listeners.add(WrappedEventListener(INPUT, options, listener))
}
}

13
web/core/src/jsMain/kotlin/androidx/compose/web/attributes/TextAreaAttrsBuilder.kt

@ -5,8 +5,8 @@
package androidx.compose.web.attributes
import org.jetbrains.compose.web.attributes.*
import org.jetbrains.compose.web.events.WrappedTextInputEvent
import org.jetbrains.compose.web.attributes.AttrsBuilder
import org.jetbrains.compose.web.attributes.Options
import org.w3c.dom.HTMLTextAreaElement
class TextAreaAttrsBuilder : AttrsBuilder<HTMLTextAreaElement>() {
@ -20,13 +20,4 @@ class TextAreaAttrsBuilder : AttrsBuilder<HTMLTextAreaElement>() {
listener(SyntheticInputEvent(text, it.nativeEvent.target as HTMLTextAreaElement, it.nativeEvent))
}
}
@Deprecated(
message = "It's not reliable as it can be applied to any input type.",
replaceWith = ReplaceWith("onInput(options, listener)"),
level = DeprecationLevel.WARNING
)
fun onTextInput(options: Options = Options.DEFAULT, listener: (WrappedTextInputEvent) -> Unit) {
listeners.add(TextInputEventListener(options, listener))
}
}

6
web/integration-core/src/jsMain/kotlin/androidx/compose/web/sample/CodeSnippetSamples.kt

@ -33,7 +33,7 @@ fun KotlinCodeSnippets() {
type = InputType.Radio,
attrs = {
name("code-snippet")
onRadioInput {
onInput {
currentSnippet.value = """
/* Adds two integers */
fun add(i: Int, j: Int): Int {
@ -47,7 +47,7 @@ fun KotlinCodeSnippets() {
type = InputType.Radio,
attrs = {
name("code-snippet")
onRadioInput {
onInput {
currentSnippet.value = """
/* Does some calculations */
fun calculate(i: Int, j: Int): Int {
@ -80,4 +80,4 @@ fun CodeSnippet(code: String, language: String = "kotlin") {
private fun HTMLElement.setHighlightedCode(code: String) {
innerText = code
HighlightJs.highlightElement(this)
}
}

16
web/integration-core/src/jsMain/kotlin/androidx/compose/web/sample/Sample.kt

@ -272,8 +272,8 @@ fun MyInputComponent(text: State<String>, onChange: (String) -> Unit) {
onKeyDown {
println("On keyDown key = : ${it.getNormalizedKey()}")
}
onTextInput {
onChange(it.inputValue)
onInput {
onChange(it.value)
}
onKeyUp {
println("On keyUp key = : ${it.getNormalizedKey()}")
@ -283,8 +283,8 @@ fun MyInputComponent(text: State<String>, onChange: (String) -> Unit) {
}
Div {
Input(type = InputType.Checkbox, attrs = {
onCheckboxInput {
println("From div - Checked: " + it.checked)
onInput {
println("From div - Checked: " + it.value)
}
})
Input(type = InputType.Text, attrs = {
@ -295,8 +295,8 @@ fun MyInputComponent(text: State<String>, onChange: (String) -> Unit) {
Input(
type = InputType.Radio,
attrs = {
onRadioInput {
println("Radio 1 - Checked: " + it.checked)
onInput {
println("Radio 1 - Checked: " + it.value)
}
name("f1")
}
@ -304,8 +304,8 @@ fun MyInputComponent(text: State<String>, onChange: (String) -> Unit) {
Input(
type = InputType.Radio,
attrs = {
onRadioInput {
println("Radio 2 - Checked: " + it.checked)
onInput {
println("Radio 2 - Checked: " + it.value)
}
name("f1")
}

5
web/widgets/src/jsMain/kotlin/layouts/slider.kt

@ -24,9 +24,8 @@ actual fun SliderActual(
attr("min", valueRange.start.toString())
attr("max", valueRange.endInclusive.toString())
attr("step", step.toString())
onRangeInput {
val value: String = it.nativeEvent.target.asDynamic().value
onValueChange(value.toFloat())
onInput {
onValueChange(it.value?.toFloat() ?: 0f)
}
}
)

Loading…
Cancel
Save