From f7b583270707f4fcfc599f9010c3dcba58c1decc Mon Sep 17 00:00:00 2001 From: Roman Volosovskyi Date: Tue, 21 Jun 2016 12:03:39 +0300 Subject: [PATCH] orientation --- android/app/build.gradle | 1 + .../main/java/com/statusim/MainActivity.java | 15 ++++++++++-- android/settings.gradle | 2 ++ package.json | 1 + src/status_im/android/core.cljs | 11 ++++++++- src/status_im/chat/views/response.cljs | 23 +++++++++++-------- src/status_im/components/react.cljs | 1 + 7 files changed, 42 insertions(+), 12 deletions(-) diff --git a/android/app/build.gradle b/android/app/build.gradle index 21e197ea42..7202b12494 100644 --- a/android/app/build.gradle +++ b/android/app/build.gradle @@ -131,6 +131,7 @@ dependencies { compile project(':react-native-linear-gradient') compile project(':ReactNativeAndroidSmsListener') compile project(':react-native-camera') + compile project(':react-native-orientation') // compile(name:'geth', ext:'aar') compile(group: 'status-im', name: 'android-geth', version: '1.4.0-201604110816-a97a114', ext: 'aar') diff --git a/android/app/src/main/java/com/statusim/MainActivity.java b/android/app/src/main/java/com/statusim/MainActivity.java index 341732d5d7..ee5ff65fd1 100644 --- a/android/app/src/main/java/com/statusim/MainActivity.java +++ b/android/app/src/main/java/com/statusim/MainActivity.java @@ -23,6 +23,7 @@ import android.content.Context; import com.bitgo.randombytes.RandomBytesPackage; import com.BV.LinearGradient.LinearGradientPackage; import com.centaurwarchief.smslistener.SmsListener; +import com.github.yamill.orientation.OrientationPackage; import android.util.Log; @@ -35,7 +36,8 @@ import java.io.File; import com.lwansbrough.RCTCamera.*; import com.i18n.reactnativei18n.ReactNativeI18n; import io.realm.react.RealmReactPackage; - +import android.content.Intent; +import android.content.res.Configuration; public class MainActivity extends ReactActivity { @@ -181,7 +183,16 @@ public class MainActivity extends ReactActivity { new RandomBytesPackage(), new LinearGradientPackage(), new RCTCameraPackage(), - new SmsListener(this) + new SmsListener(this), + new OrientationPackage(this) ); } + + @Override + public void onConfigurationChanged(Configuration newConfig) { + super.onConfigurationChanged(newConfig); + Intent intent = new Intent("onConfigurationChanged"); + intent.putExtra("newConfig", newConfig); + this.sendBroadcast(intent); + } } diff --git a/android/settings.gradle b/android/settings.gradle index 906ece37bc..ee6b7c66b3 100644 --- a/android/settings.gradle +++ b/android/settings.gradle @@ -20,3 +20,5 @@ include ':ReactNativeAndroidSmsListener' project(':ReactNativeAndroidSmsListener').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-android-sms-listener/android') include ':react-native-camera' project(':react-native-camera').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-camera/android') +include ':react-native-orientation', ':app' +project(':react-native-orientation').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-orientation/android') diff --git a/package.json b/package.json index b26cf32faf..7a3bdd9292 100644 --- a/package.json +++ b/package.json @@ -21,6 +21,7 @@ "react-native-qrcode": "^0.2.2", "react-native-randombytes": "^2.1.0", "react-native-vector-icons": "^1.3.4", + "react-native-orientation": "^1.17.0", "realm": "^0.11.1" } } diff --git a/src/status_im/android/core.cljs b/src/status_im/android/core.cljs index daecbff91c..bba5331ebf 100644 --- a/src/status_im/android/core.cljs +++ b/src/status_im/android/core.cljs @@ -5,7 +5,8 @@ [re-frame.core :refer [subscribe dispatch dispatch-sync]] [status-im.handlers] [status-im.subs] - [status-im.components.react :refer [navigator app-registry device-event-emitter]] + [status-im.components.react :refer [navigator app-registry device-event-emitter + orientation]] [status-im.components.main-tabs :refer [main-tabs]] [status-im.contacts.screen :refer [contact-list]] [status-im.contacts.views.new-contact :refer [new-contact]] @@ -33,12 +34,20 @@ true)))] (add-event-listener "hardwareBackPress" new-listener))) +(defn orientation->keyword [o] + (keyword (.toLowerCase o))) + (defn app-root [] (let [signed-up (subscribe [:get :signed-up]) view-id (subscribe [:get :view-id])] (r/create-class {:component-will-mount (fn [] + (let [o (orientation->keyword (.getInitialOrientation orientation))] + (dispatch [:set :orientation o])) + (.addOrientationListener + orientation + #(dispatch [:set :orientation (orientation->keyword %)])) (.addListener device-event-emitter "keyboardDidShow" (fn [e] diff --git a/src/status_im/chat/views/response.cljs b/src/status_im/chat/views/response.cljs index 8566da3bb9..dc41bf1833 100644 --- a/src/status_im/chat/views/response.cljs +++ b/src/status_im/chat/views/response.cljs @@ -34,11 +34,15 @@ ;; TODO stub data: request message info "By ???, MMM 1st at HH:mm"]]) -(defn create-response-pan-responder [response-height kb-height] +(defn pan-responder [response-height kb-height orientation] (drag/create-pan-responder {:on-move (fn [_ gesture] (when (> (Math/abs (.-dy gesture)) 10) - (let [to-value (- (:height (react/get-dimensions "window")) + (let [w (react/get-dimensions "window") + p (if (= :portrait @orientation) + :height + :width) + to-value (- (p w) @kb-height (.-moveY gesture))] (anim/start @@ -51,8 +55,9 @@ (.-_value response-height)])))})) (defn request-info [response-height] - (let [kb-height (subscribe [:get :keyboard-height]) - pan-responder (create-response-pan-responder response-height kb-height) + (let [orientation (subscribe [:get :orientation]) + kb-height (subscribe [:get :keyboard-height]) + pan-responder (pan-responder response-height kb-height orientation) command (subscribe [:get-chat-command])] (fn [response-height] [view (merge (drag/pan-handlers pan-responder) @@ -73,11 +78,11 @@ (defn container [response-height & children] (let [;; todo to-response-height, cur-response-height must be specific ;; for each chat - to-response-height (subscribe [:animations :to-response-height]) - changed (subscribe [:animations :response-height-changed]) - context {:to-value to-response-height - :val response-height} - on-update (container-animation-logic context)] + to-response-height (subscribe [:animations :to-response-height]) + changed (subscribe [:animations :response-height-changed]) + context {:to-value to-response-height + :val response-height} + on-update (container-animation-logic context)] (r/create-class {:component-did-mount on-update diff --git a/src/status_im/components/react.cljs b/src/status_im/components/react.cljs index 3841331b14..f931ce4e00 100644 --- a/src/status_im/components/react.cljs +++ b/src/status_im/components/react.cljs @@ -77,3 +77,4 @@ (def dismiss-keyboard! (u/require "dismissKeyboard")) (def device-event-emitter (.-DeviceEventEmitter react)) +(def orientation (u/require "react-native-orientation"))