Former-commit-id: 2887e1c502
This commit is contained in:
Roman Volosovskyi 2016-06-21 20:13:51 +03:00
parent 63034358b2
commit 977e29f4c3
1 changed files with 28 additions and 16 deletions

View File

@ -38,24 +38,36 @@
(defn enough-dy [gesture] (defn enough-dy [gesture]
(> (Math/abs (.-dy gesture)) 10)) (> (Math/abs (.-dy gesture)) 10))
(defn pan-responder [response-height kb-height orientation] (defn on-move [response-height kb-height orientation]
(drag/create-pan-responder (fn [_ gesture]
{:on-move (fn [_ gesture]
(when (enough-dy gesture) (when (enough-dy gesture)
(let [w (react/get-dimensions "window") (let [w (react/get-dimensions "window")
;; depending on orientation use height or width of screen
prop (if (= :portrait @orientation) prop (if (= :portrait @orientation)
:height :height
:width) :width)
;; subtract keyboard height to get "real height" of screen
;; then subtract gesture position to get suggestions height
;; todo maybe it is better to use margin-top instead height
;; it is not obvious
to-value (- (prop w) @kb-height (.-moveY gesture))] to-value (- (prop w) @kb-height (.-moveY gesture))]
(println to-value )
(anim/start (anim/start
(anim/spring response-height {:toValue to-value}))))) (anim/spring response-height {:toValue to-value}))))))
:on-release (fn [_ gesture]
(defn on-release [response-height]
(fn [_ gesture]
(when (enough-dy gesture) (when (enough-dy gesture)
(dispatch [:fix-response-height (dispatch [:fix-response-height
(.-vy gesture) (.-vy gesture)
;; todo access to "private" property ;; todo access to "private" property
;; better to find another way... ;; better to find another way...
(.-_value response-height)])))})) (.-_value response-height)]))))
(defn pan-responder [response-height kb-height orientation]
(drag/create-pan-responder
{:on-move (on-move response-height kb-height orientation)
:on-release (on-release response-height)}))
(defn request-info [response-height] (defn request-info [response-height]
(let [orientation (subscribe [:get :orientation]) (let [orientation (subscribe [:get :orientation])