Skip to content

Commit

Permalink
iOS fixed for formatting, base path improvement
Browse files Browse the repository at this point in the history
  • Loading branch information
UnknownJoe796 committed Nov 8, 2024
1 parent 2869e25 commit fac65ce
Show file tree
Hide file tree
Showing 9 changed files with 72 additions and 18 deletions.
2 changes: 1 addition & 1 deletion example-app-android/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ android {
targetCompatibility = JavaVersion.VERSION_1_8
}
dependencies {
coreLibraryDesugaring("com.android.tools:desugar_jdk_libs:2.0.4")
coreLibraryDesugaring("com.android.tools:desugar_jdk_libs:2.1.3")
}
kotlinOptions {
jvmTarget = "1.8"
Expand Down
2 changes: 1 addition & 1 deletion example-app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ android {
targetCompatibility = JavaVersion.VERSION_1_8
}
dependencies {
coreLibraryDesugaring("com.android.tools:desugar_jdk_libs:2.0.4")
coreLibraryDesugaring("com.android.tools:desugar_jdk_libs:2.1.3")
}
}

Expand Down
1 change: 1 addition & 0 deletions example-app/src/jsMain/resources/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width,initial-scale=1">
<base href="http://localhost:5175/">
<title>JS Client</title>
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="stylesheet" href="/experimental.css" />
Expand Down
2 changes: 1 addition & 1 deletion library/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ android {
targetCompatibility = JavaVersion.VERSION_1_8
}
dependencies {
coreLibraryDesugaring("com.android.tools:desugar_jdk_libs:2.1.2")
coreLibraryDesugaring("com.android.tools:desugar_jdk_libs:2.1.3")
}
testOptions {
unitTests {
Expand Down
2 changes: 1 addition & 1 deletion library/library.podspec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Pod::Spec.new do |spec|
spec.name = 'library'
spec.version = 'phone-number-input-SNAPSHOT'
spec.version = 'version-3-SNAPSHOT'
spec.homepage = ''
spec.source = { :http=> ''}
spec.authors = ''
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,45 @@ import android.widget.EditText
import android.widget.TextView
import androidx.core.graphics.TypefaceCompat
import androidx.core.view.updateLayoutParams
import androidx.core.widget.doAfterTextChanged
import com.lightningkite.kiteui.models.*
import com.lightningkite.kiteui.reactive.Action
import com.lightningkite.kiteui.reactive.ImmediateWritable
import com.lightningkite.kiteui.reactive.lens
import com.lightningkite.kiteui.utils.numberAutocommaRepair
import com.lightningkite.kiteui.utils.repairFormatAndPosition
import com.lightningkite.kiteui.views.RContext
import com.lightningkite.kiteui.views.RViewWithAction

actual class FormattedTextInput actual constructor(context: RContext) : RViewWithAction(context) {
override val native = EditText(context.activity)
override val native = EditText(context.activity).apply {
var block = false
doAfterTextChanged { _ ->
if(block) return@doAfterTextChanged
block = true
post {
val str = this.text.toString()
try {
if (str == null) return@post
repairFormatAndPosition(
dirty = str,
selectionStart = selectionStart,
selectionEnd = selectionEnd,
setResult = {
setText(it)
},
setSelectionRange = { start, end ->
setSelection(start, end)
},
isRawData = isRawData,
formatter = formatter,
)
} finally {
block = false
}
}
}
}
override fun applyForeground(theme: Theme) {
super.applyForeground(theme)
native.setTextColor(theme.foreground.colorInt())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -277,11 +277,14 @@ class LazyPropertyTests {
val basis = Property("Test")
val lazy = LazyProperty(stopListeningWhenOverridden = false) { basis() }
val lensed = lazy.lens { it.take(3) }
val lensed2 = lazy.lens(get = { it.take(3) }, modify = { o, it -> it })
testContext {
println(lensed.state)
load {
println("Starting")
println(lensed())
assertEquals("Tes", lensed())
}
load {
assertEquals("Tes", lensed2())
}
}
}
Expand All @@ -290,15 +293,23 @@ class LazyPropertyTests {
val basis = Property("Test")
val lazy = LazyProperty(stopListeningWhenOverridden = false) { basis() }
val lensed = lazy.lens { it.take(3) }
val lensed2 = lazy.lens(get = { it.take(3) }, modify = { o, it -> it })
var value = ""
var value2 = ""
testContext {
println(lensed.state)
reactive {
println("Starting")
value = lensed()
println(value)
}
reactive {
println("Starting")
value2 = lensed2()
println(value2)
}
assertEquals("Tes", value)
assertEquals("Tes", value2)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,11 @@ import com.lightningkite.kiteui.reactive.ImmediateWritable
import com.lightningkite.kiteui.reactive.onRemove
import com.lightningkite.kiteui.utils.commaString
import com.lightningkite.kiteui.utils.numberAutocommaRepair
import com.lightningkite.kiteui.utils.repairFormatAndPosition
import com.lightningkite.kiteui.views.*
import platform.Foundation.*
import platform.UIKit.*
import platform.darwin.NSObject

actual class FormattedTextInput actual constructor(context: RContext) : RViewWithAction(context) {
override val native = WrapperView()
Expand All @@ -23,11 +27,11 @@ actual class FormattedTextInput actual constructor(context: RContext) : RViewWit

init {
var block = false
textField.onEvent(this@NumberInput, UIControlEventEditingChanged) {
textField.onEvent(this@FormattedTextInput, UIControlEventEditingChanged) {
if (block) return@onEvent
block = true
try {
numberAutocommaRepair(
repairFormatAndPosition(
dirty = textField.text ?: "",
selectionStart = textField.selectedTextRange?.start?.let { textField.offsetFromPosition(textField.beginningOfDocument, it) }?.toInt(),
selectionEnd = textField.selectedTextRange?.end?.let { textField.offsetFromPosition(textField.beginningOfDocument, it) }?.toInt(),
Expand All @@ -36,16 +40,19 @@ actual class FormattedTextInput actual constructor(context: RContext) : RViewWit
},
setSelectionRange = { start, end ->
textField.selectedTextRange = textField.textRangeFromPosition(
textField.positionFromPosition(textField.beginningOfDocument, start.toLong()) ?: return@numberAutocommaRepair,
textField.positionFromPosition(textField.beginningOfDocument, end.toLong()) ?: return@numberAutocommaRepair,
textField.positionFromPosition(textField.beginningOfDocument, start.toLong()) ?: return@repairFormatAndPosition,
textField.positionFromPosition(textField.beginningOfDocument, end.toLong()) ?: return@repairFormatAndPosition,
)
}
},
isRawData = isRawData,
formatter = formatter,
)
} finally {
block = false
}
}
}

override fun applyForeground(theme: Theme) {
textField.textColor = theme.foreground.closestColor().toUiColor()
fontAndStyle = theme.font
Expand Down Expand Up @@ -86,6 +93,7 @@ actual class FormattedTextInput actual constructor(context: RContext) : RViewWit
this.isRawData = isRawData
this.formatter = formatter
}

actual val content: ImmediateWritable<String> = object : ImmediateWritable<String> {
override var value: String
get() = (textField.text ?: "").filter(isRawData)
Expand All @@ -96,7 +104,7 @@ actual class FormattedTextInput actual constructor(context: RContext) : RViewWit
}

override fun addListener(listener: () -> Unit): () -> Unit {
return textField.onEvent(this@NumberInput, UIControlEventEditingChanged, listener)
return textField.onEvent(this@FormattedTextInput, UIControlEventEditingChanged, listener)
}
}

Expand Down Expand Up @@ -125,12 +133,13 @@ actual class FormattedTextInput actual constructor(context: RContext) : RViewWit
}
textField.secureTextEntry = value.autocomplete in setOf(AutoComplete.Password, AutoComplete.NewPassword)
}

override fun actionSet(value: Action?) {
super.actionSet(value)
textField.delegate = value?.let {
val d = object : NSObject(), UITextFieldDelegateProtocol {
override fun textFieldShouldReturn(textField: UITextField): Boolean {
it?.startAction(this@NumberInput)
it?.startAction(this@FormattedTextInput)
return true
}
}
Expand All @@ -153,6 +162,7 @@ actual class FormattedTextInput actual constructor(context: RContext) : RViewWit
else -> UIReturnKeyType.UIReturnKeyDone
}
}

actual var hint: String = ""
set(value) {
field = value
Expand Down Expand Up @@ -187,16 +197,18 @@ actual class FormattedTextInput actual constructor(context: RContext) : RViewWit
textField.enabled = value
refreshTheming()
}

init {
onRemove(textField.observe("highlighted", { refreshTheming() }))
onRemove(textField.observe("selected", { refreshTheming() }))
onRemove(textField.observe("enabled", { refreshTheming() }))
}

override fun applyState(theme: ThemeAndBack): ThemeAndBack {
var t = theme
if(!textField.enabled) t = t[DisabledSemantic]
if(textField.highlighted) t = t[DownSemantic]
if(textField.focused) t = t[FocusSemantic]
if (!textField.enabled) t = t[DisabledSemantic]
if (textField.highlighted) t = t[DownSemantic]
if (textField.focused) t = t[FocusSemantic]
return super.applyState(t)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ external interface BaseUrlScript {

var basePath = (document.getElementById("baseUrlLocation") as? HTMLScriptElement)?.innerText?.let {
JSON.parse<BaseUrlScript>(it).baseUrl
} ?: "/"
} ?: document.baseURI.takeIf { document.getElementsByTagName("base").length != 0 } ?: "/"

private fun Location.urlLike() = UrlLikePath(
segments = pathname.removePrefix(basePath).split('/').filter { it.isNotBlank() },
Expand Down

0 comments on commit fac65ce

Please sign in to comment.