Skip to content
This repository was archived by the owner on Apr 25, 2024. It is now read-only.

Make config handle proxies of android.* classses #70

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions src/clojure/neko/ui.clj
Original file line number Diff line number Diff line change
Expand Up @@ -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))

Expand Down Expand Up @@ -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.
Expand Down
13 changes: 11 additions & 2 deletions test/neko/t_ui.clj
Original file line number Diff line number Diff line change
Expand Up @@ -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]))

Expand Down Expand Up @@ -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
Expand Down