From 3b80f7d088f81a4c74120ebbf14e63b6019ebde3 Mon Sep 17 00:00:00 2001 From: alwx Date: Wed, 25 Jan 2017 14:43:15 +0300 Subject: [PATCH] /browse links (addition to #638) --- .re-natal | 4 +-- env/dev/env/android/main.cljs | 2 +- src/status_im/chat/views/message.cljs | 9 ++--- src/status_im/components/list_selection.cljs | 37 ++++++++++++++++++++ src/status_im/components/react.cljs | 1 + src/status_im/components/share.cljs | 12 ------- src/status_im/handlers.cljs | 14 -------- src/status_im/profile/screen.cljs | 2 +- src/status_im/translations/en.cljs | 5 +++ 9 files changed, 52 insertions(+), 34 deletions(-) create mode 100644 src/status_im/components/list_selection.cljs delete mode 100644 src/status_im/components/share.cljs diff --git a/.re-natal b/.re-natal index deff5dd006..ab65546af0 100644 --- a/.re-natal +++ b/.re-natal @@ -42,9 +42,9 @@ "imageDirs": [ "images" ], - "iosHost": "10.0.1.4", + "iosHost": "localhost", "envRoots": { "dev": "env/dev", "prod": "env/prod" } -} +} \ No newline at end of file diff --git a/env/dev/env/android/main.cljs b/env/dev/env/android/main.cljs index a26f34785c..6813b594fe 100644 --- a/env/dev/env/android/main.cljs +++ b/env/dev/env/android/main.cljs @@ -14,7 +14,7 @@ (re-frame.core/dispatch [:load-commands!])) (figwheel/watch-and-reload - :websocket-url "ws://10.0.3.2:3449/figwheel-ws" + :websocket-url "ws://localhost:3449/figwheel-ws" :heads-up-display false :jsload-callback callback) diff --git a/src/status_im/chat/views/message.cljs b/src/status_im/chat/views/message.cljs index 5a4b33b63c..1fa508e909 100644 --- a/src/status_im/chat/views/message.cljs +++ b/src/status_im/chat/views/message.cljs @@ -15,7 +15,7 @@ get-dimensions]] [status-im.components.animation :as anim] [status-im.chat.constants :as chat-consts] - [status-im.components.share :refer [share]] + [status-im.components.list-selection :refer [share browse]] [status-im.chat.views.request-message :refer [message-content-command-request]] [status-im.chat.styles.message :as st] [status-im.chat.styles.command-pill :as pill-st] @@ -203,9 +203,10 @@ (let [parsed-text (parse-text content) simple-text? (= (count parsed-text) 2)] (if simple-text? - [autolink {:style (st/text-message message) - :font :default - :text (apply str parsed-text)}] + [autolink {:style (st/text-message message) + :font :default + :text (apply str parsed-text) + :onPress #(browse %)}] [text {:style (st/text-message message) :font :default} (parse-text content)]))]) diff --git a/src/status_im/components/list_selection.cljs b/src/status_im/components/list_selection.cljs new file mode 100644 index 0000000000..5cd31c40ea --- /dev/null +++ b/src/status_im/components/list_selection.cljs @@ -0,0 +1,37 @@ +(ns status-im.components.list-selection + (:require [re-frame.core :refer [dispatch]] + [status-im.components.react :refer [copy-to-clipboard + linking]] + [status-im.utils.platform :refer [platform-specific]] + [status-im.i18n :refer [label]])) + +(def class (js/require "react-native-share")) + +(defn open [opts] + (.open class (clj->js opts))) + +(defn share [text dialog-title] + (let [list-selection-fn (:list-selection-fn platform-specific)] + (list-selection-fn {:title dialog-title + :options [(label :t/sharing-copy-to-clipboard) (label :t/sharing-share)] + :callback (fn [index] + (case index + 0 (copy-to-clipboard text) + 1 (open {:message text}) + :default)) + :cancel-text (label :t/sharing-cancel)}))) + +(defn browse [link] + (let [list-selection-fn (:list-selection-fn platform-specific)] + (list-selection-fn {:title (label :t/browsing-title) + :options [(label :t/browsing-browse) (label :t/browsing-open-in-web-browser)] + :callback (fn [index] + (case index + 0 (do + (dispatch [:set-chat-command :browse]) + (dispatch [:fill-chat-command-content link]) + (js/setTimeout #(dispatch [:send-command!]) 500)) + 1 (.openURL linking link) + :default)) + :cancel-text (label :t/browsing-cancel)}))) + diff --git a/src/status_im/components/react.cljs b/src/status_im/components/react.cljs index 830bbb1101..ac60feb7be 100644 --- a/src/status_im/components/react.cljs +++ b/src/status_im/components/react.cljs @@ -49,6 +49,7 @@ (def dimensions (.-Dimensions js/ReactNative)) (def keyboard (.-Keyboard react-native)) +(def linking (.-Linking js/ReactNative)) ;; Accessor methods for React Components diff --git a/src/status_im/components/share.cljs b/src/status_im/components/share.cljs deleted file mode 100644 index d9ad53c982..0000000000 --- a/src/status_im/components/share.cljs +++ /dev/null @@ -1,12 +0,0 @@ -(ns status-im.components.share - (:require [re-frame.core :refer [dispatch]] - [status-im.utils.platform :refer [platform-specific]])) - -(def class (js/require "react-native-share")) - -(defn open [opts] - (.open class (clj->js opts))) - -(defn share [text dialog-title] - (let [list-selection-fn (:list-selection-fn platform-specific)] - (dispatch [:open-sharing list-selection-fn text dialog-title]))) diff --git a/src/status_im/handlers.cljs b/src/status_im/handlers.cljs index 4cf21e07bf..2e0e7223c0 100644 --- a/src/status_im/handlers.cljs +++ b/src/status_im/handlers.cljs @@ -6,8 +6,6 @@ [taoensso.timbre :as log] [status-im.utils.crypt :refer [gen-random-bytes]] [status-im.components.status :as status] - [status-im.components.share :refer [open]] - [status-im.components.react :refer [copy-to-clipboard]] [status-im.utils.handlers :refer [register-handler] :as u] status-im.chat.handlers status-im.group-settings.handlers @@ -46,18 +44,6 @@ (fn [db [_ k v]] (assoc-in db [:animations k] v))) -(register-handler :open-sharing - (u/side-effect! - (fn [_ [_ list-selection-fn text dialog-title]] - (list-selection-fn {:title dialog-title - :options [(label :t/sharing-copy-to-clipboard) (label :t/sharing-share)] - :callback (fn [index] - (case index - 0 (copy-to-clipboard text) - 1 (open {:message text}) - :default)) - :cancel-text (label :t/sharing-cancel)})))) - (register-handler :initialize-db (fn [{:keys [status-module-initialized? network-status network]} _] (data-store/init) diff --git a/src/status_im/profile/screen.cljs b/src/status_im/profile/screen.cljs index f5b21d4838..c1aa18be1d 100644 --- a/src/status_im/profile/screen.cljs +++ b/src/status_im/profile/screen.cljs @@ -22,7 +22,7 @@ [status-im.components.text-field.view :refer [text-field]] [status-im.components.selectable-field.view :refer [selectable-field]] [status-im.components.status-view.view :refer [status-view]] - [status-im.components.share :refer [share]] + [status-im.components.list-selection :refer [share]] [status-im.utils.phone-number :refer [format-phone-number]] [status-im.utils.image-processing :refer [img->base64]] [status-im.utils.platform :refer [platform-specific]] diff --git a/src/status_im/translations/en.cljs b/src/status_im/translations/en.cljs index 43df175ba7..dfbe79438b 100644 --- a/src/status_im/translations/en.cljs +++ b/src/status_im/translations/en.cljs @@ -88,6 +88,11 @@ :sharing-share "Share..." :sharing-cancel "Cancel" + :browsing-title "Browse" + :browsing-browse "/browse" + :browsing-open-in-web-browser "Open in web browser" + :browsing-cancel "Cancel" + ;sign-up :contacts-syncronized "Your contacts have been synchronized" :confirmation-code (str "Thanks! We've sent you a text message with a confirmation "