我使用lein-fruit生成了一个基本的 Clojure 项目,该项目通过RoboVM以 iOS 为目标。我引入了 core.async 来沿通道传递按钮点击,但是改变go
块中的按钮似乎没有效果。
是否有理由相信 core.async 的 Java 实现在 RoboVM 下不起作用?
这是我的代码,从基本的 lein-fruit 模板稍作修改。
(ns core-async-demo.core
(:require [core-async-demo.core-utils :as u]
[clojure.core.async :refer [go chan put! <!]]))
(def window (atom nil))
(def taps (chan))
(defn init
[]
(let [main-screen (u/static-method :uikit.UIScreen :getMainScreen)
button-type (u/static-field :uikit.UIButtonType :RoundedRect)
button (u/static-method :uikit.UIButton :fromType button-type)
normal-state (u/static-field :uikit.UIControlState :Normal)
click-count (atom 0)]
(doto button
(.setFrame (u/init-class :coregraphics.CGRect 115 121 91 37))
(.setTitle "Click me!" normal-state)
(.addOnTouchUpInsideListener
(proxy [org.robovm.cocoatouch.uikit.UIControl$OnTouchUpInsideListener] []
(onTouchUpInside [control event]
(put! taps true)))))
(reset! window (u/init-class :uikit.UIWindow (.getBounds main-screen)))
(go
(loop [_ (<! taps)]
(.setTitle button (str "Click #" (swap! click-count inc)) normal-state)
(recur (<! taps))))
(doto @window
(.setBackgroundColor (u/static-method :uikit.UIColor :lightGrayColor))
(.addSubview button)
.makeKeyAndVisible)))