app/internal/window: [iOS] move main thread dispatch to Go

Signed-off-by: Elias Naur <mail@eliasnaur.com>
This commit is contained in:
Elias Naur
2020-05-17 14:58:33 +02:00
parent 77899c79d9
commit fc0c046cab
2 changed files with 21 additions and 17 deletions
+18 -8
View File
@@ -200,14 +200,19 @@ func onTouch(last C.int, view, touchRef C.CFTypeRef, phase C.NSInteger, x, y C.C
} }
func (w *window) SetAnimating(anim bool) { func (w *window) SetAnimating(anim bool) {
if w.view == 0 { v := w.view
if v == 0 {
return return
} }
var animi C.int var animi C.int
if anim { if anim {
animi = 1 animi = 1
} }
C.gio_setAnimating(w.view, animi) C.CFRetain(v)
runOnMain(func() {
defer C.CFRelease(v)
C.gio_setAnimating(v, animi)
})
} }
func (w *window) onKeyCommand(name string) { func (w *window) onKeyCommand(name string) {
@@ -245,14 +250,19 @@ func (w *window) isVisible() bool {
} }
func (w *window) ShowTextInput(show bool) { func (w *window) ShowTextInput(show bool) {
if w.view == 0 { v := w.view
if v == 0 {
return return
} }
if show { C.CFRetain(v)
C.gio_showTextInput(w.view) runOnMain(func() {
} else { defer C.CFRelease(v)
C.gio_hideTextInput(w.view) if show {
} C.gio_showTextInput(w.view)
} else {
C.gio_hideTextInput(w.view)
}
})
} }
func NewWindow(win Callbacks, opts *Options) error { func NewWindow(win Callbacks, opts *Options) error {
+3 -9
View File
@@ -281,23 +281,17 @@ NSArray<UIKeyCommand *> *_keyCommands;
void gio_setAnimating(CFTypeRef viewRef, int anim) { void gio_setAnimating(CFTypeRef viewRef, int anim) {
GioView *view = (__bridge GioView *)viewRef; GioView *view = (__bridge GioView *)viewRef;
dispatch_async(dispatch_get_main_queue(), ^{ [view setAnimating:(anim ? YES : NO)];
[view setAnimating:(anim ? YES : NO)];
});
} }
void gio_showTextInput(CFTypeRef viewRef) { void gio_showTextInput(CFTypeRef viewRef) {
UIView *view = (__bridge UIView *)viewRef; UIView *view = (__bridge UIView *)viewRef;
dispatch_async(dispatch_get_main_queue(), ^{ [view becomeFirstResponder];
[view becomeFirstResponder];
});
} }
void gio_hideTextInput(CFTypeRef viewRef) { void gio_hideTextInput(CFTypeRef viewRef) {
UIView *view = (__bridge UIView *)viewRef; UIView *view = (__bridge UIView *)viewRef;
dispatch_async(dispatch_get_main_queue(), ^{ [view resignFirstResponder];
[view resignFirstResponder];
});
} }
void gio_addLayerToView(CFTypeRef viewRef, CFTypeRef layerRef) { void gio_addLayerToView(CFTypeRef viewRef, CFTypeRef layerRef) {