Skip to content

Commit 4a76b5e

Browse files
committed
support rotation
1 parent 64a591f commit 4a76b5e

File tree

3 files changed

+54
-1
lines changed

3 files changed

+54
-1
lines changed

Diff for: project.clj

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
[org.clojure/clojurescript "0.0-2280"]]
88

99
:hooks [leiningen.cljsbuild]
10-
10+
:profiles {:dev {:plugins [[com.cemerick/austin "0.1.5"]]}}
1111
:plugins [[lein-cljsbuild "1.0.3"]]
1212
:source-paths ["src/clj"]
1313
:cljsbuild

Diff for: src/cljs/calabash_script/core.cljs

+47
Original file line numberDiff line numberDiff line change
@@ -256,6 +256,53 @@
256256
(.touchAndHold (utils/target) (utils/uia-point offset) duration))
257257

258258

259+
(def orientations
260+
{js/UIA_DEVICE_ORIENTATION_UNKNOWN :unknown
261+
js/UIA_DEVICE_ORIENTATION_PORTRAIT :portrait
262+
js/UIA_DEVICE_ORIENTATION_PORTRAIT_UPSIDEDOWN :portrait-upside-down
263+
js/UIA_DEVICE_ORIENTATION_LANDSCAPELEFT :landscape-left
264+
js/UIA_DEVICE_ORIENTATION_LANDSCAPERIGHT :landscape-right
265+
js/UIA_DEVICE_ORIENTATION_FACEUP :faceup
266+
js/UIA_DEVICE_ORIENTATION_FACEDOWN :facedown})
267+
268+
(def rotatable-orientations
269+
[js/UIA_DEVICE_ORIENTATION_PORTRAIT
270+
js/UIA_DEVICE_ORIENTATION_LANDSCAPERIGHT ;portrait rotated clockwise
271+
js/UIA_DEVICE_ORIENTATION_PORTRAIT_UPSIDEDOWN ;landscaperight rotated clockwise
272+
js/UIA_DEVICE_ORIENTATION_LANDSCAPELEFT]) ;...
273+
274+
(def clockwise-orientations
275+
(partition 2 1 (cycle rotatable-orientations)))
276+
277+
;;((:portrait :landscape-right) ;; clockwise of :portrait is :landscape-right
278+
;; (:landscape-right :portrait-upside-down) ;; ..
279+
;; (:portrait-upside-down :landscape-left))
280+
281+
282+
(defn relative-orientation
283+
[orientation dir]
284+
(if (some #(= orientation %) rotatable-orientations)
285+
(let [dir (case dir
286+
:left :counter-clockwise
287+
:right :clockwise
288+
dir)
289+
orientations (if (= :clockwise dir)
290+
clockwise-orientations
291+
(map reverse clockwise-orientations))]
292+
(second (first (filter #(= orientation (first %)) orientations))))
293+
(throw (new js/Error (str "Can't rotate orientation: " orientation)))))
294+
295+
(defn orientation
296+
[]
297+
(get orientations (.deviceOrientation (utils/target))))
298+
299+
(defn rotate
300+
[dir]
301+
(.setDeviceOrientation (utils/target)
302+
(relative-orientation
303+
(.deviceOrientation (utils/target))
304+
dir)))
305+
259306
;;; Alerts ;;;
260307

261308
(def ^:dynamic *alert-handlers*

Diff for: src/cljs/calabash_script/exports.cljs

+6
Original file line numberDiff line numberDiff line change
@@ -84,3 +84,9 @@
8484
(def ^:export waitForElementsReady (wrap-query-fn core/wait-for-elements-ready))
8585
(defn ^:export waitForMarkReady [wait-opts mark]
8686
(core/wait-for-mark-ready (reader/read-string wait-opts) mark))
87+
88+
(defn ^:export rotate [dir]
89+
(core/rotate (keyword (reader/read-string dir))))
90+
91+
(defn ^:export orientation []
92+
(str (core/orientation)))

0 commit comments

Comments
 (0)