-
Notifications
You must be signed in to change notification settings - Fork 985
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
03bc273
commit bb5e5e2
Showing
3 changed files
with
54 additions
and
92 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,67 +1,30 @@ | ||
(ns status-im.ui.components.controls.view | ||
(:require [cljs-bean.core :as bean] | ||
[react-native.reanimated :as animated] | ||
[status-im.ui.components.controls.styles :as styles] | ||
(:require [status-im.ui.components.controls.styles :as styles] | ||
[status-im.ui.components.colors :as colors] | ||
[react-native.core :as rn] | ||
[reagent.core :as reagent] | ||
[status-im.ui.components.icons.icons :as icons])) | ||
|
||
(defn control-builder | ||
[component] | ||
(fn [props] | ||
(let [{:keys [value onChange disabled]} | ||
(bean/bean props)] | ||
(reagent/as-element | ||
[rn/touchable-without-feedback | ||
{:on-press (fn [] | ||
(when (and (not disabled) onChange) | ||
(onChange (not value)))) | ||
:enabled (boolean (and onChange (not disabled)))} | ||
[rn/view | ||
[component | ||
{:disabled disabled}]]])))) | ||
|
||
(defn switch-view | ||
[{:keys [transition hold disabled value]}] | ||
[animated/view | ||
{:style (styles/switch-style transition disabled) | ||
(defn switch | ||
[{:keys [disabled value]}] | ||
[rn/view | ||
{:style (styles/switch-style value disabled) | ||
:accessibility-label (str "switch-" (if value "on" "off")) | ||
:accessibility-role :switch} | ||
[animated/view {:style (styles/switch-bullet-style transition hold)}]]) | ||
[rn/view {:style (styles/switch-bullet-style value false)}]]) | ||
|
||
(defn radio-view | ||
[{:keys [transition hold disabled value]}] | ||
[animated/view | ||
{:style (styles/radio-style transition disabled) | ||
(defn radio | ||
[{:keys [disabled value]}] | ||
[rn/view | ||
{:style (styles/radio-style value disabled) | ||
:accessibility-label (str "radio-" (if value "on" "off")) | ||
:accessibility-role :radio} | ||
[animated/view {:style (styles/radio-bullet-style transition hold)}]]) | ||
|
||
(defn checkbox-view | ||
[props] | ||
(let [{:keys [value onChange disabled]} (bean/bean props)] | ||
(reagent/as-element | ||
[rn/touchable-without-feedback | ||
{:on-press (when (and onChange (not disabled)) onChange)} | ||
[rn/view | ||
{:style (styles/checkbox-style value disabled) | ||
:accessibility-label (str "checkbox-" (if value "on" "off")) | ||
:accessibility-role :checkbox} | ||
[rn/view {:style (styles/check-icon-style value)} | ||
[icons/tiny-icon :tiny-icons/tiny-check {:color colors/white}]]]]))) | ||
[rn/view {:style (styles/radio-bullet-style value false)}]]) | ||
|
||
(defn animated-checkbox-view | ||
[{:keys [transition hold disabled value]}] | ||
[animated/view | ||
{:style (styles/animated-checkbox-style transition disabled) | ||
(defn checkbox | ||
[{:keys [value disabled]}] | ||
[rn/view | ||
{:style (styles/checkbox-style value disabled) | ||
:accessibility-label (str "checkbox-" (if value "on" "off")) | ||
:accessibility-role :checkbox} | ||
[animated/view {:style (styles/animated-check-icon-style transition hold)} | ||
[rn/view {:style (styles/check-icon-style value)} | ||
[icons/tiny-icon :tiny-icons/tiny-check {:color colors/white}]]]) | ||
|
||
(def switch (reagent/adapt-react-class (control-builder switch-view))) | ||
(def radio (reagent/adapt-react-class (control-builder radio-view))) | ||
(def animated-checkbox | ||
(reagent/adapt-react-class (control-builder animated-checkbox-view))) | ||
(def checkbox (reagent/adapt-react-class checkbox-view)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters