diff --git a/src/clojure/neko/ui.clj b/src/clojure/neko/ui.clj index d98d9c9..f541cca 100644 --- a/src/clojure/neko/ui.clj +++ b/src/clojure/neko/ui.clj @@ -3,7 +3,8 @@ (:require [neko.ui.mapping :as kw] [neko.ui.traits :refer [apply-trait]] [neko.-utils :refer [keyword->setter reflect-setter - reflect-constructor]]) + reflect-constructor + closest-android-ancestor]]) (:import android.content.res.Configuration neko.App)) @@ -95,7 +96,8 @@ "Takes a widget and key-value pairs of attributes, and applies these attributes to the widget." [widget & {:as attributes}] - (apply-attributes (kw/keyword-by-classname (type widget)) + (apply-attributes (kw/keyword-by-classname (closest-android-ancestor + (class widget))) widget attributes {})) ;; ## Compatibility with Android XML UI facilities. diff --git a/test/neko/t_ui.clj b/test/neko/t_ui.clj index 001d220..f3bb702 100644 --- a/test/neko/t_ui.clj +++ b/test/neko/t_ui.clj @@ -6,6 +6,7 @@ (:import [android.widget Button LinearLayout TextView] android.content.pm.ActivityInfo android.view.View + android.widget.LinearLayout neko.App [org.robolectric Robolectric RuntimeEnvironment])) @@ -72,12 +73,20 @@ (is (= "hello" (.getText b)))))) (deftest config - (let [v (ui/make-ui RuntimeEnvironment/application [:button {:text "hello"}])] + (let [v (ui/make-ui RuntimeEnvironment/application [:button {:text "hello"}]) + ll (ui/make-ui RuntimeEnvironment/application + [:linear-layout {:custom-constructor + (fn [ctx] + (proxy [LinearLayout] [ctx])) + :orientation :vertical}])] (is (= View/VISIBLE (.getVisibility v))) (is (= "hello" (.getText v))) (ui/config v :text "updated" :visibility View/GONE) (is (= "updated" (.getText v))) - (is (= View/GONE (.getVisibility v))))) + (is (= View/GONE (.getVisibility v))) + (is (= LinearLayout/VERTICAL(.getOrientation ll))) + (ui/config ll :orientation :horizontal) + (is (= LinearLayout/HORIZONTAL (.getOrientation ll))))) (deftest inflate-layout (is (instance? TextView (ui/inflate-layout RuntimeEnvironment/application