34 lines
887 B
Go
34 lines
887 B
Go
package naive
|
|
|
|
import (
|
|
"github.com/progrium/darwinkit/dispatch"
|
|
"github.com/progrium/darwinkit/macos/appkit"
|
|
"github.com/progrium/darwinkit/macos/foundation"
|
|
)
|
|
|
|
func (tiv TextInputView) toNative() appkit.IView {
|
|
ntiv := appkit.NewTextField()
|
|
if tiv.Value != nil {
|
|
ntiv.SetStringValue(tiv.Value.Value())
|
|
if eff, ok := tiv.Value.(*Effect[string]); ok {
|
|
tfd := &appkit.TextFieldDelegate{}
|
|
tfd.SetControlTextDidChange(func(obj foundation.Notification) {
|
|
dispatch.MainQueue().DispatchAsync(func() {
|
|
if ntiv.StringValue() != eff.value {
|
|
eff.SetValue(ntiv.StringValue())
|
|
}
|
|
})
|
|
})
|
|
ntiv.SetDelegate(tfd)
|
|
eff.OnChange(ntiv.SetStringValue)
|
|
}
|
|
}
|
|
if tiv.Placeholder != nil {
|
|
ntiv.SetPlaceholderString(tiv.Placeholder.Value())
|
|
if eff, ok := tiv.Placeholder.(*Effect[string]); ok {
|
|
eff.OnChange(ntiv.SetPlaceholderString)
|
|
}
|
|
}
|
|
return ntiv
|
|
}
|