fixed icon fn definition

Signed-off-by: Andrey Shovkoplyas <motor4ik@gmail.com>
This commit is contained in:
Andrey Shovkoplyas 2018-07-25 15:53:29 +03:00
parent 9a02bca975
commit b9cbb28663
No known key found for this signature in database
GPG Key ID: EAAB7C8622D860A4

View File

@ -27,173 +27,177 @@
(def defs (get-class "Defs")) (def defs (get-class "Defs"))
(def circle (get-class "Circle"))) (def circle (get-class "Circle")))
(if platform/desktop? (def icons
(def icons {:icons/discover (js/require "./resources/icons/bottom/discover_gray.svg") (if platform/desktop?
:icons/contacts (js/require "./resources/icons/bottom/contacts_gray.svg") {:icons/discover (js/require "./resources/icons/bottom/discover_gray.svg")
:icons/home (js/require "./resources/icons/bottom/home_gray.svg") :icons/contacts (js/require "./resources/icons/bottom/contacts_gray.svg")
:icons/home-active (js/require "./resources/icons/bottom/home_blue.svg") :icons/home (js/require "./resources/icons/bottom/home_gray.svg")
:icons/profile (js/require "./resources/icons/bottom/profile_gray.svg") :icons/home-active (js/require "./resources/icons/bottom/home_blue.svg")
:icons/profile-active (js/require "./resources/icons/bottom/profile_blue.svg") :icons/profile (js/require "./resources/icons/bottom/profile_gray.svg")
:icons/wallet (js/require "./resources/icons/bottom/wallet_gray.svg") :icons/profile-active (js/require "./resources/icons/bottom/profile_blue.svg")
:icons/wallet-active (js/require "./resources/icons/bottom/wallet_active.svg") :icons/wallet (js/require "./resources/icons/bottom/wallet_gray.svg")
:icons/speaker (js/require "./resources/icons/speaker.svg") :icons/wallet-active (js/require "./resources/icons/bottom/wallet_active.svg")
:icons/speaker-off (js/require "./resources/icons/speaker_off.svg") :icons/speaker (js/require "./resources/icons/speaker.svg")
:icons/transaction-history (js/require "./resources/icons/transaction_history.svg") :icons/speaker-off (js/require "./resources/icons/speaker_off.svg")
:icons/add (js/require "./resources/icons/add.svg") :icons/transaction-history (js/require "./resources/icons/transaction_history.svg")
:icons/add-contact (js/require "./resources/icons/add_contact.svg") :icons/add (js/require "./resources/icons/add.svg")
:icons/add-wallet (js/require "./resources/icons/add_wallet.svg") :icons/add-contact (js/require "./resources/icons/add_contact.svg")
:icons/address (js/require "./resources/icons/address.svg") :icons/add-wallet (js/require "./resources/icons/add_wallet.svg")
:icons/arrow-left (js/require "./resources/icons/arrow_left.svg") :icons/address (js/require "./resources/icons/address.svg")
:icons/arrow-right (js/require "./resources/icons/arrow_right.svg") :icons/arrow-left (js/require "./resources/icons/arrow_left.svg")
:icons/flash-active (js/require "./resources/icons/flash_active.svg") :icons/arrow-right (js/require "./resources/icons/arrow_right.svg")
:icons/flash-inactive (js/require "./resources/icons/flash_inactive.svg") :icons/flash-active (js/require "./resources/icons/flash_active.svg")
:icons/attach (js/require "./resources/icons/attach.svg") :icons/flash-inactive (js/require "./resources/icons/flash_inactive.svg")
:icons/browse (js/require "./resources/icons/browse.svg") :icons/attach (js/require "./resources/icons/attach.svg")
:icons/close (js/require "./resources/icons/close.svg") :icons/browse (js/require "./resources/icons/browse.svg")
:icons/copy-from (js/require "./resources/icons/copy_from.svg") :icons/close (js/require "./resources/icons/close.svg")
:icons/delete (js/require "./resources/icons/delete.svg") :icons/copy-from (js/require "./resources/icons/copy_from.svg")
:icons/dots-horizontal (js/require "./resources/icons/dots_horizontal.svg") :icons/delete (js/require "./resources/icons/delete.svg")
:icons/dots-vertical (js/require "./resources/icons/dots_vertical.svg") :icons/dots-horizontal (js/require "./resources/icons/dots_horizontal.svg")
:icons/exclamation-mark (js/require "./resources/icons/exclamation_mark.svg") :icons/dots-vertical (js/require "./resources/icons/dots_vertical.svg")
:icons/filter (js/require "./resources/icons/filter.svg") :icons/exclamation-mark (js/require "./resources/icons/exclamation_mark.svg")
:icons/fullscreen (js/require "./resources/icons/fullscreen.svg") :icons/filter (js/require "./resources/icons/filter.svg")
:icons/group-big (js/require "./resources/icons/group_big.svg") :icons/fullscreen (js/require "./resources/icons/fullscreen.svg")
:icons/group-chat (js/require "./resources/icons/group_chat.svg") :icons/group-big (js/require "./resources/icons/group_big.svg")
:icons/chats (js/require "./resources/icons/chats.svg") :icons/group-chat (js/require "./resources/icons/group_chat.svg")
:icons/hamburger (js/require "./resources/icons/hamburger.svg") :icons/chats (js/require "./resources/icons/chats.svg")
:icons/hidden (js/require "./resources/icons/hidden.svg") :icons/hamburger (js/require "./resources/icons/hamburger.svg")
:icons/in-contacts (js/require "./resources/icons/in_contacts.svg") :icons/hidden (js/require "./resources/icons/hidden.svg")
:icons/lock (js/require "./resources/icons/lock.svg") :icons/in-contacts (js/require "./resources/icons/in_contacts.svg")
:icons/mic (js/require "./resources/icons/mic.svg") :icons/lock (js/require "./resources/icons/lock.svg")
:icons/ok (js/require "./resources/icons/ok.svg") :icons/mic (js/require "./resources/icons/mic.svg")
:icons/public (js/require "./resources/icons/public.svg") :icons/ok (js/require "./resources/icons/ok.svg")
:icons/public-chat (js/require "./resources/icons/public_chat.svg") :icons/public (js/require "./resources/icons/public.svg")
:icons/qr (js/require "./resources/icons/QR.svg") :icons/public-chat (js/require "./resources/icons/public_chat.svg")
:icons/input-commands (js/require "./resources/icons/input_commands.svg") :icons/qr (js/require "./resources/icons/QR.svg")
:icons/input-send (js/require "./resources/icons/input_send.svg") :icons/input-commands (js/require "./resources/icons/input_commands.svg")
:icons/back (js/require "./resources/icons/back.svg") :icons/input-send (js/require "./resources/icons/input_send.svg")
:icons/forward (js/require "./resources/icons/forward.svg") :icons/back (js/require "./resources/icons/back.svg")
:icons/dropdown-up (js/require "./resources/icons/dropdown_up.svg") :icons/forward (js/require "./resources/icons/forward.svg")
:icons/up (js/require "./resources/icons/up.svg") :icons/dropdown-up (js/require "./resources/icons/dropdown_up.svg")
:icons/down (js/require "./resources/icons/down.svg") :icons/up (js/require "./resources/icons/up.svg")
:icons/grab (js/require "./resources/icons/grab.svg") :icons/down (js/require "./resources/icons/down.svg")
:icons/share (js/require "./resources/icons/share.svg") :icons/grab (js/require "./resources/icons/grab.svg")
:icons/tooltip-triangle (js/require "./resources/icons/tooltip-triangle.svg") :icons/share (js/require "./resources/icons/share.svg")
:icons/open (js/require "./resources/icons/open.svg") :icons/tooltip-triangle (js/require "./resources/icons/tooltip-triangle.svg")
:icons/network (js/require "./resources/icons/network.svg") :icons/open (js/require "./resources/icons/open.svg")
:icons/wnode (js/require "./resources/icons/wnode.svg") :icons/network (js/require "./resources/icons/network.svg")
:icons/refresh (js/require "./resources/icons/refresh.svg") :icons/wnode (js/require "./resources/icons/wnode.svg")
:icons/newchat (js/require "./resources/icons/newchat.svg") :icons/refresh (js/require "./resources/icons/refresh.svg")
:icons/logo (js/require "./resources/icons/logo.svg") :icons/newchat (js/require "./resources/icons/newchat.svg")
:icons/camera (js/require "./resources/icons/camera.svg") :icons/logo (js/require "./resources/icons/logo.svg")
:icons/check (js/require "./resources/icons/check.svg") :icons/camera (js/require "./resources/icons/camera.svg")
:icons/dots (js/require "./resources/icons/dots.svg") :icons/check (js/require "./resources/icons/check.svg")
:icons/warning (js/require "./resources/icons/warning.svg")}) :icons/dots (js/require "./resources/icons/dots.svg")
(def icons {:icons/discover (components.svg/slurp-svg "./resources/icons/bottom/discover_gray.svg") :icons/warning (js/require "./resources/icons/warning.svg")}
:icons/contacts (components.svg/slurp-svg "./resources/icons/bottom/contacts_gray.svg") {:icons/discover (components.svg/slurp-svg "./resources/icons/bottom/discover_gray.svg")
:icons/home (components.svg/slurp-svg "./resources/icons/bottom/home_gray.svg") :icons/contacts (components.svg/slurp-svg "./resources/icons/bottom/contacts_gray.svg")
:icons/home-active (components.svg/slurp-svg "./resources/icons/bottom/home_blue.svg") :icons/home (components.svg/slurp-svg "./resources/icons/bottom/home_gray.svg")
:icons/profile (components.svg/slurp-svg "./resources/icons/bottom/profile_gray.svg") :icons/home-active (components.svg/slurp-svg "./resources/icons/bottom/home_blue.svg")
:icons/profile-active (components.svg/slurp-svg "./resources/icons/bottom/profile_blue.svg") :icons/profile (components.svg/slurp-svg "./resources/icons/bottom/profile_gray.svg")
:icons/wallet (components.svg/slurp-svg "./resources/icons/bottom/wallet_gray.svg") :icons/profile-active (components.svg/slurp-svg "./resources/icons/bottom/profile_blue.svg")
:icons/wallet-active (components.svg/slurp-svg "./resources/icons/bottom/wallet_active.svg") :icons/wallet (components.svg/slurp-svg "./resources/icons/bottom/wallet_gray.svg")
:icons/speaker (components.svg/slurp-svg "./resources/icons/speaker.svg") :icons/wallet-active (components.svg/slurp-svg "./resources/icons/bottom/wallet_active.svg")
:icons/speaker-off (components.svg/slurp-svg "./resources/icons/speaker_off.svg") :icons/speaker (components.svg/slurp-svg "./resources/icons/speaker.svg")
:icons/transaction-history (components.svg/slurp-svg "./resources/icons/transaction_history.svg") :icons/speaker-off (components.svg/slurp-svg "./resources/icons/speaker_off.svg")
:icons/add (components.svg/slurp-svg "./resources/icons/add.svg") :icons/transaction-history (components.svg/slurp-svg "./resources/icons/transaction_history.svg")
:icons/add-contact (components.svg/slurp-svg "./resources/icons/add_contact.svg") :icons/add (components.svg/slurp-svg "./resources/icons/add.svg")
:icons/add-wallet (components.svg/slurp-svg "./resources/icons/add_wallet.svg") :icons/add-contact (components.svg/slurp-svg "./resources/icons/add_contact.svg")
:icons/address (components.svg/slurp-svg "./resources/icons/address.svg") :icons/add-wallet (components.svg/slurp-svg "./resources/icons/add_wallet.svg")
:icons/arrow-left (components.svg/slurp-svg "./resources/icons/arrow_left.svg") :icons/address (components.svg/slurp-svg "./resources/icons/address.svg")
:icons/arrow-right (components.svg/slurp-svg "./resources/icons/arrow_right.svg") :icons/arrow-left (components.svg/slurp-svg "./resources/icons/arrow_left.svg")
:icons/flash-active (components.svg/slurp-svg "./resources/icons/flash_active.svg") :icons/arrow-right (components.svg/slurp-svg "./resources/icons/arrow_right.svg")
:icons/flash-inactive (components.svg/slurp-svg "./resources/icons/flash_inactive.svg") :icons/flash-active (components.svg/slurp-svg "./resources/icons/flash_active.svg")
:icons/attach (components.svg/slurp-svg "./resources/icons/attach.svg") :icons/flash-inactive (components.svg/slurp-svg "./resources/icons/flash_inactive.svg")
:icons/browse (components.svg/slurp-svg "./resources/icons/browse.svg") :icons/attach (components.svg/slurp-svg "./resources/icons/attach.svg")
:icons/close (components.svg/slurp-svg "./resources/icons/close.svg") :icons/browse (components.svg/slurp-svg "./resources/icons/browse.svg")
:icons/copy-from (components.svg/slurp-svg "./resources/icons/copy_from.svg") :icons/close (components.svg/slurp-svg "./resources/icons/close.svg")
:icons/delete (components.svg/slurp-svg "./resources/icons/delete.svg") :icons/copy-from (components.svg/slurp-svg "./resources/icons/copy_from.svg")
:icons/dots-horizontal (components.svg/slurp-svg "./resources/icons/dots_horizontal.svg") :icons/delete (components.svg/slurp-svg "./resources/icons/delete.svg")
:icons/dots-vertical (components.svg/slurp-svg "./resources/icons/dots_vertical.svg") :icons/dots-horizontal (components.svg/slurp-svg "./resources/icons/dots_horizontal.svg")
:icons/exclamation-mark (components.svg/slurp-svg "./resources/icons/exclamation_mark.svg") :icons/dots-vertical (components.svg/slurp-svg "./resources/icons/dots_vertical.svg")
:icons/filter (components.svg/slurp-svg "./resources/icons/filter.svg") :icons/exclamation-mark (components.svg/slurp-svg "./resources/icons/exclamation_mark.svg")
:icons/fullscreen (components.svg/slurp-svg "./resources/icons/fullscreen.svg") :icons/filter (components.svg/slurp-svg "./resources/icons/filter.svg")
:icons/group-big (components.svg/slurp-svg "./resources/icons/group_big.svg") :icons/fullscreen (components.svg/slurp-svg "./resources/icons/fullscreen.svg")
:icons/group-chat (components.svg/slurp-svg "./resources/icons/group_chat.svg") :icons/group-big (components.svg/slurp-svg "./resources/icons/group_big.svg")
:icons/chats (components.svg/slurp-svg "./resources/icons/chats.svg") :icons/group-chat (components.svg/slurp-svg "./resources/icons/group_chat.svg")
:icons/hamburger (components.svg/slurp-svg "./resources/icons/hamburger.svg") :icons/chats (components.svg/slurp-svg "./resources/icons/chats.svg")
:icons/hidden (components.svg/slurp-svg "./resources/icons/hidden.svg") :icons/hamburger (components.svg/slurp-svg "./resources/icons/hamburger.svg")
:icons/in-contacts (components.svg/slurp-svg "./resources/icons/in_contacts.svg") :icons/hidden (components.svg/slurp-svg "./resources/icons/hidden.svg")
:icons/lock (components.svg/slurp-svg "./resources/icons/lock.svg") :icons/in-contacts (components.svg/slurp-svg "./resources/icons/in_contacts.svg")
:icons/mic (components.svg/slurp-svg "./resources/icons/mic.svg") :icons/lock (components.svg/slurp-svg "./resources/icons/lock.svg")
:icons/ok (components.svg/slurp-svg "./resources/icons/ok.svg") :icons/mic (components.svg/slurp-svg "./resources/icons/mic.svg")
:icons/public (components.svg/slurp-svg "./resources/icons/public.svg") :icons/ok (components.svg/slurp-svg "./resources/icons/ok.svg")
:icons/public-chat (components.svg/slurp-svg "./resources/icons/public_chat.svg") :icons/public (components.svg/slurp-svg "./resources/icons/public.svg")
:icons/qr (components.svg/slurp-svg "./resources/icons/QR.svg") :icons/public-chat (components.svg/slurp-svg "./resources/icons/public_chat.svg")
:icons/input-commands (components.svg/slurp-svg "./resources/icons/input_commands.svg") :icons/qr (components.svg/slurp-svg "./resources/icons/QR.svg")
:icons/input-send (components.svg/slurp-svg "./resources/icons/input_send.svg") :icons/input-commands (components.svg/slurp-svg "./resources/icons/input_commands.svg")
:icons/back (components.svg/slurp-svg "./resources/icons/back.svg") :icons/input-send (components.svg/slurp-svg "./resources/icons/input_send.svg")
:icons/forward (components.svg/slurp-svg "./resources/icons/forward.svg") :icons/back (components.svg/slurp-svg "./resources/icons/back.svg")
:icons/dropdown-up (components.svg/slurp-svg "./resources/icons/dropdown_up.svg") :icons/forward (components.svg/slurp-svg "./resources/icons/forward.svg")
:icons/up (components.svg/slurp-svg "./resources/icons/up.svg") :icons/dropdown-up (components.svg/slurp-svg "./resources/icons/dropdown_up.svg")
:icons/down (components.svg/slurp-svg "./resources/icons/down.svg") :icons/up (components.svg/slurp-svg "./resources/icons/up.svg")
:icons/grab (components.svg/slurp-svg "./resources/icons/grab.svg") :icons/down (components.svg/slurp-svg "./resources/icons/down.svg")
:icons/share (components.svg/slurp-svg "./resources/icons/share.svg") :icons/grab (components.svg/slurp-svg "./resources/icons/grab.svg")
:icons/tooltip-triangle (components.svg/slurp-svg "./resources/icons/tooltip-triangle.svg") :icons/share (components.svg/slurp-svg "./resources/icons/share.svg")
:icons/open (components.svg/slurp-svg "./resources/icons/open.svg") :icons/tooltip-triangle (components.svg/slurp-svg "./resources/icons/tooltip-triangle.svg")
:icons/network (components.svg/slurp-svg "./resources/icons/network.svg") :icons/open (components.svg/slurp-svg "./resources/icons/open.svg")
:icons/wnode (components.svg/slurp-svg "./resources/icons/wnode.svg") :icons/network (components.svg/slurp-svg "./resources/icons/network.svg")
:icons/refresh (components.svg/slurp-svg "./resources/icons/refresh.svg") :icons/wnode (components.svg/slurp-svg "./resources/icons/wnode.svg")
:icons/newchat (components.svg/slurp-svg "./resources/icons/newchat.svg") :icons/refresh (components.svg/slurp-svg "./resources/icons/refresh.svg")
:icons/logo (components.svg/slurp-svg "./resources/icons/logo.svg") :icons/newchat (components.svg/slurp-svg "./resources/icons/newchat.svg")
:icons/camera (components.svg/slurp-svg "./resources/icons/camera.svg") :icons/logo (components.svg/slurp-svg "./resources/icons/logo.svg")
:icons/check (components.svg/slurp-svg "./resources/icons/check.svg") :icons/camera (components.svg/slurp-svg "./resources/icons/camera.svg")
:icons/dots (components.svg/slurp-svg "./resources/icons/dots.svg") :icons/check (components.svg/slurp-svg "./resources/icons/check.svg")
:icons/warning (components.svg/slurp-svg "./resources/icons/warning.svg")})) :icons/dots (components.svg/slurp-svg "./resources/icons/dots.svg")
:icons/warning (components.svg/slurp-svg "./resources/icons/warning.svg")}))
(defn normalize-property-name [n] (defn normalize-property-name [n]
(if (= n :icons/options) (if (= n :icons/options)
(if platform/ios? :icons/dots-horizontal :icons/dots-vertical) (if platform/ios? :icons/dots-horizontal :icons/dots-vertical)
n)) n))
(if platform/desktop? (defn desktop-icon
(do (def default-viewbox {:width 24 :height 24}) [name {:keys [color container-style style accessibility-label width height]
:or {accessibility-label :icon}}]
(let [default-viewbox {:width 24 :height 24}
icon-style (if width
(assoc default-viewbox :width width :height height)
default-viewbox)]
[react/view {:style container-style
:accessibility-label accessibility-label}
[react/image {:source (get icons (normalize-property-name name))
:style (merge icon-style style)}]]))
(defn icon (defn mobile-icon
([name] (icon name nil)) [name {:keys [color container-style style accessibility-label width height]
([name {:keys [color container-style style accessibility-label width height] :or {accessibility-label :icon}}]
:or {accessibility-label :icon}}] ^{:key name}
(let [icon-style (if width [react/view {:style container-style
(assoc default-viewbox :width width :height height) :accessibility-label accessibility-label}
default-viewbox)] (if-let [icon-fn (get icons (normalize-property-name name))]
[react/view {:style container-style (let [icon-vec (icon-fn
:accessibility-label accessibility-label} (cond
[react/image {:source (get icons (normalize-property-name name)) (keyword? color)
:style (merge icon-style style)}]])))) (case color
(do (defn icon :dark styles/icon-dark-color
([name] (icon name nil)) :gray styles/icon-gray-color
([name {:keys [color container-style style accessibility-label width height] :blue styles/color-light-blue
:or {accessibility-label :icon}}] :active styles/color-blue4
^{:key name} :white styles/color-white
[react/view {:style container-style :red styles/icon-red-color
:accessibility-label accessibility-label} styles/icon-dark-color)
(if-let [icon-fn (get icons (normalize-property-name name))] (string? color)
(let [icon-vec (icon-fn color
(cond :else
(keyword? color) styles/icon-dark-color))]
(case color (if width
:dark styles/icon-dark-color (update icon-vec 1 assoc :width width :height height)
:gray styles/icon-gray-color icon-vec))
:blue styles/color-light-blue (throw (js/Error. (str "Unknown icon: " name))))])
:active styles/color-blue4
:white styles/color-white (defn icon
:red styles/icon-red-color ([name] (icon name nil))
styles/icon-dark-color) ([name options]
(string? color) (let [icon-fn (if platform/desktop? desktop-icon mobile-icon)]
color [icon-fn name options])))
:else
styles/icon-dark-color))]
(if width
(update icon-vec 1 assoc :width width :height height)
icon-vec))
(throw (js/Error. (str "Unknown icon: " name))))]))))