Skip to content

Commit

Permalink
Add done to the numberInput tool bar
Browse files Browse the repository at this point in the history
  • Loading branch information
kf7mxe committed Dec 6, 2024
1 parent 13a1329 commit f1ad79b
Showing 1 changed file with 22 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package com.lightningkite.kiteui.views.direct


import com.lightningkite.kiteui.models.*
import com.lightningkite.kiteui.reactive.CalculationContext
import com.lightningkite.kiteui.reactive.Action
import com.lightningkite.kiteui.reactive.ImmediateWritable
import com.lightningkite.kiteui.reactive.ReadableState
Expand All @@ -14,17 +15,29 @@ import kotlinx.cinterop.ExperimentalForeignApi
import platform.Foundation.*
import platform.UIKit.*
import platform.darwin.NSObject

import platform.objc.sel_registerName
import com.lightningkite.kiteui.WeakReference
import kotlinx.cinterop.ObjCAction


actual class NumberInput actual constructor(context: RContext) : RViewWithAction(context) {
override val native = WrapperView()
val toolbar = UIToolbar().apply {
barStyle = UIBarStyleDefault
setTranslucent(true)
sizeToFit()
setItems(listOf(
UIBarButtonItem(barButtonSystemItem = UIBarButtonSystemItem.UIBarButtonSystemItemFlexibleSpace, target = null, action = null),
UIBarButtonItem(title = "Done", style = UIBarButtonItemStyle.UIBarButtonItemStylePlain, target = this@NumberInput, action =sel_registerName("done")),
), animated = false)
}
val textField = UITextField().apply {
smartDashesType = UITextSmartDashesType.UITextSmartDashesTypeNo
smartQuotesType = UITextSmartQuotesType.UITextSmartQuotesTypeNo
backgroundColor = UIColor.clearColor
keyboardType = UIKeyboardTypeNumberPad
keyboardType = UIKeyboardTypeDecimalPad
delegate = NextFocusDelegateShared
inputAccessoryView = toolbar
}

init {
Expand Down Expand Up @@ -56,6 +69,7 @@ actual class NumberInput actual constructor(context: RContext) : RViewWithAction
}
}
}

override fun applyForeground(theme: Theme) {
textField.textColor = theme.foreground.closestColor().toUiColor()
fontAndStyle = theme.font
Expand Down Expand Up @@ -117,6 +131,12 @@ actual class NumberInput actual constructor(context: RContext) : RViewWithAction
}
textField.secureTextEntry = value.autocomplete in setOf(AutoComplete.Password, AutoComplete.NewPassword)
}

@ObjCAction
fun done() {
action?.startAction(this@NumberInput)
}

override fun actionSet(value: Action?) {
super.actionSet(value)
textField.delegate = value?.let {
Expand Down

0 comments on commit f1ad79b

Please sign in to comment.