-
Notifications
You must be signed in to change notification settings - Fork 984
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: add floating button page component (#17737)
Co-authored-by: Ulises M <ulises.ssb@hotmail.com>
- Loading branch information
1 parent
98e529b
commit 67e3a78
Showing
16 changed files
with
370 additions
and
10 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
32 changes: 32 additions & 0 deletions
32
src/status_im2/common/floating_button_page/component_spec.cljs
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 |
---|---|---|
@@ -0,0 +1,32 @@ | ||
(ns status-im2.common.floating-button-page.component-spec | ||
(:require [quo.core :as quo] | ||
[status-im2.common.floating-button-page.view :as floating-button-page] | ||
[test-helpers.component :as h])) | ||
|
||
(h/describe "floating button page" | ||
(h/test "renders with a header and standard button" | ||
(h/render [floating-button-page/view | ||
{:header [quo/page-nav | ||
{:type :title-description | ||
:title "floating button page" | ||
:description "press right icon to swap button type" | ||
:text-align :left | ||
:background :blur | ||
:icon-name :i/close}] | ||
:footer [quo/button {} "continue"]}]) | ||
(h/is-truthy (h/get-by-text "continue")) | ||
(h/is-truthy (h/get-by-text "floating button page"))) | ||
|
||
(h/test "renders with a header and a slide button" | ||
(h/render [floating-button-page/view | ||
{:header [quo/page-nav | ||
{:type :title-description | ||
:title "floating button page" | ||
:description "press right icon to swap button type" | ||
:text-align :left | ||
:background :blur | ||
:icon-name :i/close}] | ||
:footer [quo/slide-button | ||
{:track-text "We gotta slide" | ||
:track-icon :face-id}]}]) | ||
(h/is-truthy (h/get-by-text "We gotta slide")))) |
17 changes: 17 additions & 0 deletions
17
src/status_im2/common/floating_button_page/floating_container/style.cljs
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 |
---|---|---|
@@ -0,0 +1,17 @@ | ||
(ns status-im2.common.floating-button-page.floating-container.style | ||
(:require [react-native.safe-area :as safe-area])) | ||
|
||
(defn content-container | ||
[blur? keyboard-shown?] | ||
(let [margin-bottom (if keyboard-shown? 0 (safe-area/get-bottom))] | ||
(cond-> {:margin-top :auto | ||
:overflow :hidden | ||
:margin-bottom margin-bottom | ||
:padding-vertical 12 | ||
:padding-horizontal 20} | ||
blur? (dissoc :padding-vertical :padding-horizontal)))) | ||
|
||
(def blur-inner-container | ||
{:background-color :transparent ; required, otherwise blur-view will shrink | ||
:padding-vertical 12 | ||
:padding-horizontal 20}) |
25 changes: 25 additions & 0 deletions
25
src/status_im2/common/floating_button_page/floating_container/view.cljs
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 |
---|---|---|
@@ -0,0 +1,25 @@ | ||
(ns status-im2.common.floating-button-page.floating-container.view | ||
(:require [quo.theme :as quo.theme] | ||
[react-native.blur :as blur] | ||
[react-native.core :as rn] | ||
[status-im2.common.floating-button-page.floating-container.style :as style])) | ||
|
||
(defn- blur-container | ||
[child theme] | ||
[blur/view | ||
{:blur-amount 12 | ||
:blur-radius 12 | ||
:blur-type (quo.theme/theme-value :light :dark theme)} | ||
[rn/view {:style style/blur-inner-container} | ||
child]]) | ||
|
||
(defn view-internal | ||
[{:keys [theme on-layout keyboard-shown? blur?]} child] | ||
[rn/view | ||
{:style (style/content-container blur? keyboard-shown?) | ||
:on-layout on-layout} | ||
(if blur? | ||
[blur-container child theme] | ||
child)]) | ||
|
||
(def view (quo.theme/with-theme view-internal)) |
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 |
---|---|---|
@@ -0,0 +1,15 @@ | ||
(ns status-im2.common.floating-button-page.style) | ||
|
||
(def page-container | ||
{:position :absolute | ||
:top 0 | ||
:bottom 0 | ||
:left 0 | ||
:right 0}) | ||
|
||
(def keyboard-avoiding-view | ||
{:position :absolute | ||
:top 0 | ||
:bottom 0 | ||
:left 0 | ||
:right 0}) |
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 |
---|---|---|
@@ -0,0 +1,102 @@ | ||
(ns status-im2.common.floating-button-page.view | ||
(:require | ||
[oops.core :as oops] | ||
[react-native.core :as rn] | ||
[react-native.platform :as platform] | ||
[react-native.safe-area :as safe-area] | ||
[reagent.core :as reagent] | ||
[status-im2.common.floating-button-page.floating-container.view :as floating-container] | ||
[status-im2.common.floating-button-page.style :as style])) | ||
|
||
(defn- show-background | ||
[{:keys [window-height keyboard-height footer-container-height content-scroll-y | ||
content-container-height header-height keyboard-shown?]}] | ||
(let [available-space (- window-height | ||
(safe-area/get-top) | ||
header-height | ||
keyboard-height ; Already contains the bottom safe area value | ||
footer-container-height) | ||
scroll-view-height (- content-container-height content-scroll-y) | ||
overlap? (< available-space scroll-view-height)] | ||
(and keyboard-shown? overlap?))) | ||
|
||
(defn- set-height-on-layout | ||
[ratom] | ||
(fn [event] | ||
(let [height (oops/oget event "nativeEvent.layout.height")] | ||
(reset! ratom height)))) | ||
|
||
(defn- init-keyboard-listeners | ||
[{:keys [on-did-show]}] | ||
(let [keyboard-will-show? (reagent/atom false) | ||
keyboard-did-show? (reagent/atom false) | ||
add-listener (fn [listener callback] | ||
(oops/ocall rn/keyboard "addListener" listener callback)) | ||
will-show-listener (add-listener "keyboardWillShow" | ||
#(reset! keyboard-will-show? true)) | ||
did-show-listener (add-listener "keyboardDidShow" | ||
(fn [e] | ||
(reset! keyboard-did-show? true) | ||
(when on-did-show (on-did-show e)))) | ||
will-hide-listener (add-listener "keyboardWillHide" | ||
#(reset! keyboard-will-show? false)) | ||
did-hide-listener (add-listener "keyboardDidHide" | ||
#(reset! keyboard-did-show? false)) | ||
remove-listeners (fn [] | ||
(doseq [listener [will-show-listener will-hide-listener | ||
did-show-listener did-hide-listener]] | ||
(oops/ocall listener "remove")))] | ||
{:keyboard-will-show? keyboard-will-show? | ||
:keyboard-did-show? keyboard-did-show? | ||
:remove-listeners remove-listeners})) | ||
|
||
(defn view | ||
[{:keys [header footer]} & children] | ||
(reagent/with-let [window-height (:height (rn/get-window)) | ||
footer-container-height (reagent/atom 0) | ||
header-height (reagent/atom 0) | ||
content-container-height (reagent/atom 0) | ||
content-scroll-y (reagent/atom 0) | ||
keyboard-height (reagent/atom 0) | ||
{:keys [keyboard-will-show? | ||
keyboard-did-show? | ||
remove-listeners]} (init-keyboard-listeners | ||
{:on-did-show | ||
(fn [e] | ||
(reset! keyboard-height | ||
(oops/oget e "endCoordinates.height")))}) | ||
set-header-height (set-height-on-layout header-height) | ||
set-content-container-height (set-height-on-layout content-container-height) | ||
set-footer-container-height (set-height-on-layout footer-container-height) | ||
set-content-y-scroll (fn [event] | ||
(reset! content-scroll-y | ||
(oops/oget event "nativeEvent.contentOffset.y")))] | ||
(let [keyboard-shown? (if platform/ios? @keyboard-will-show? @keyboard-did-show?) | ||
show-background? (show-background {:window-height window-height | ||
:footer-container-height @footer-container-height | ||
:keyboard-height @keyboard-height | ||
:content-scroll-y @content-scroll-y | ||
:content-container-height @content-container-height | ||
:header-height @header-height | ||
:keyboard-shown? keyboard-shown?})] | ||
|
||
[rn/view {:style style/page-container} | ||
[rn/view {:on-layout set-header-height} | ||
header] | ||
[rn/scroll-view | ||
{:on-scroll set-content-y-scroll | ||
:scroll-event-throttle 64 | ||
:content-container-style {:flex-grow 1}} | ||
(into [rn/view {:on-layout set-content-container-height}] | ||
children)] | ||
[rn/keyboard-avoiding-view | ||
{:style style/keyboard-avoiding-view | ||
:keyboard-vertical-offset (if platform/ios? (safe-area/get-top) 0) | ||
:pointer-events :box-none} | ||
[floating-container/view | ||
{:on-layout set-footer-container-height | ||
:keyboard-shown? keyboard-shown? | ||
:blur? show-background?} | ||
footer]]]) | ||
(finally | ||
(remove-listeners)))) |
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
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
22 changes: 22 additions & 0 deletions
22
src/status_im2/contexts/status_im_preview/common/floating_button_page/style.cljs
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 |
---|---|---|
@@ -0,0 +1,22 @@ | ||
(ns status-im2.contexts.status-im-preview.common.floating-button-page.style | ||
(:require [quo.foundations.colors :as colors] | ||
[react-native.safe-area :as safe-area])) | ||
|
||
(defn container | ||
[] | ||
{:flex 1 | ||
:margin-top (safe-area/get-top)}) | ||
|
||
(def background-image | ||
{:position :absolute | ||
:top (- (safe-area/get-top)) | ||
:left 0 | ||
:right 0 | ||
:bottom 200}) | ||
|
||
(defn page-content | ||
[height] | ||
{:flex 1 | ||
:height height | ||
:overflow :hidden | ||
:background-color (colors/resolve-color :army 30)}) |
55 changes: 55 additions & 0 deletions
55
src/status_im2/contexts/status_im_preview/common/floating_button_page/view.cljs
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 |
---|---|---|
@@ -0,0 +1,55 @@ | ||
(ns status-im2.contexts.status-im-preview.common.floating-button-page.view | ||
(:require [quo.core :as quo] | ||
[re-frame.core :as rf] | ||
[react-native.core :as rn] | ||
[reagent.core :as reagent] | ||
[status-im2.common.floating-button-page.view :as floating-button-page] | ||
[status-im2.common.resources :as resources] | ||
[status-im2.contexts.status-im-preview.common.floating-button-page.style :as style])) | ||
|
||
(defn view | ||
[] | ||
(let [content-height (reagent/atom 450) | ||
slide? (reagent/atom false)] | ||
(fn [] | ||
[rn/view {:style (style/container)} | ||
(when-not @slide? | ||
[rn/image | ||
{:style style/background-image | ||
:source (resources/get-mock-image :dark-blur-bg)}]) | ||
[floating-button-page/view | ||
{:header [quo/page-nav | ||
{:type :title-description | ||
:title "floating button page" | ||
:description "press right icon to swap button type" | ||
:text-align :left | ||
:right-side [{:icon-name :i/swap | ||
:on-press #(swap! slide? not)}] | ||
:background :blur | ||
:icon-name :i/close | ||
:on-press #(rf/dispatch [:navigate-back])}] | ||
:footer (if @slide? | ||
[quo/slide-button | ||
{:track-text "We gotta slide" | ||
:track-icon :face-id | ||
:container-style {:z-index 2} | ||
:customization-color :blue | ||
:on-complete #(js/alert "button slid")} | ||
"Save address"] | ||
[quo/button | ||
{:container-style {:z-index 2} | ||
:on-press #(js/alert "button pressed")} | ||
"Save address"])} | ||
[rn/view {:style (style/page-content @content-height)} | ||
[quo/text {:size :heading-1} "Page Content"] | ||
[quo/input | ||
{:auto-focus true | ||
:value ""}] | ||
[quo/button | ||
{:type :outline | ||
:on-press #(swap! content-height (fn [v] (+ v 10)))} | ||
"increase height"] | ||
[quo/button | ||
{:type :outline | ||
:on-press #(swap! content-height (fn [v] (- v 10)))} | ||
"decrease height"]]]]))) |
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 |
---|---|---|
@@ -0,0 +1,59 @@ | ||
(ns status-im2.contexts.status-im-preview.main | ||
(:refer-clojure :exclude [filter]) | ||
(:require | ||
[quo.core :as quo] | ||
[react-native.core :as rn] | ||
[reagent.core :as reagent] | ||
[status-im2.contexts.quo-preview.common :as common] | ||
[status-im2.contexts.status-im-preview.common.floating-button-page.view :as floating-button-page] | ||
[status-im2.contexts.status-im-preview.style :as style] | ||
[utils.re-frame :as rf])) | ||
|
||
(def screens-categories | ||
{:common [{:name :floating-button-page | ||
:component floating-button-page/view}]}) | ||
|
||
(defn- category-view | ||
[] | ||
(let [open? (reagent/atom false) | ||
on-press #(swap! open? not)] | ||
(fn [category] | ||
[rn/view {:style {:margin-vertical 8}} | ||
[quo/dropdown | ||
{:type :grey | ||
:state (if @open? :active :default) | ||
:on-press on-press} | ||
(name (key category))] | ||
(when @open? | ||
(for [{category-name :name} (val category)] | ||
^{:key category-name} | ||
[quo/button | ||
{:type :outline | ||
:container-style {:margin-vertical 8} | ||
:on-press #(rf/dispatch [:navigate-to category-name])} | ||
(name category-name)]))]))) | ||
|
||
(defn- main-screen | ||
[] | ||
[:<> | ||
[common/navigation-bar {:title "Status IM components"}] | ||
[rn/scroll-view {:style (style/main)} | ||
(for [category (sort screens-categories)] | ||
^{:key (first category)} | ||
[category-view category])]]) | ||
|
||
(def screens | ||
(->> screens-categories | ||
(map val) | ||
flatten | ||
(map (fn [subcategory] | ||
(update-in subcategory | ||
[:options :topBar] | ||
merge | ||
{:visible false}))))) | ||
|
||
(def main-screens | ||
[{:name :status-im-preview | ||
:options {:topBar {:visible false} | ||
:insets {:top? true}} | ||
:component main-screen}]) |
Oops, something went wrong.