-
Notifications
You must be signed in to change notification settings - Fork 983
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
- Loading branch information
Showing
19 changed files
with
423 additions
and
33 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{:hooks {:analyze-call {taoensso.encore/defalias taoensso.encore/defalias}}} |
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,16 @@ | ||
(ns taoensso.encore | ||
(:require | ||
[clj-kondo.hooks-api :as hooks])) | ||
|
||
(defn defalias [{:keys [node]}] | ||
(let [[sym-raw src-raw] (rest (:children node)) | ||
src (if src-raw src-raw sym-raw) | ||
sym (if src-raw | ||
sym-raw | ||
(symbol (name (hooks/sexpr src))))] | ||
{:node (with-meta | ||
(hooks/list-node | ||
[(hooks/token-node 'def) | ||
(hooks/token-node (hooks/sexpr sym)) | ||
(hooks/token-node (hooks/sexpr src))]) | ||
(meta src))})) |
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
18 changes: 18 additions & 0 deletions
18
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,18 @@ | ||
(ns status-im2.common.floating-button-page.floating-container.style | ||
(:require [react-native.platform :as platform])) | ||
|
||
(def container | ||
{:width "100%" | ||
:margin-top :auto | ||
:align-self :flex-end}) | ||
|
||
(def view-container | ||
(assoc container | ||
:padding-left 20 | ||
:padding-right 20 | ||
:padding-top 12 | ||
:padding-bottom 12)) | ||
|
||
(def blur-container | ||
(merge container | ||
(when platform/android? {:padding-bottom 12}))) |
69 changes: 69 additions & 0 deletions
69
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,69 @@ | ||
(ns status-im2.common.floating-button-page.floating-container.view | ||
(:require [quo.foundations.colors :as colors] | ||
[quo.theme :as quo.theme] | ||
[react-native.blur :as blur] | ||
[react-native.core :as rn] | ||
[react-native.reanimated :as reanimated] | ||
[react-native.safe-area :as safe-area] | ||
[status-im2.common.floating-button-page.floating-container.style :as style])) | ||
|
||
(def duration 110) | ||
|
||
(defn blur-container-props | ||
[theme] | ||
{:blur-amount 12 | ||
:blur-radius 25 | ||
:blur-type (quo.theme/theme-value :light :dark theme) | ||
:style {:width "100%" | ||
:padding-horizontal 20 | ||
:padding-vertical 12} | ||
:background-color (colors/theme-colors colors/white-70-blur colors/neutral-80-opa-1-blur theme)}) | ||
|
||
|
||
(defn- blur-container | ||
[props & children] | ||
[rn/view | ||
(merge props | ||
{:width "100%" | ||
:overflow :hidden}) | ||
(into [blur/view (blur-container-props (:theme props))] children)]) | ||
|
||
" | ||
- on-layout : will trigger to dynamically get the height of the container to screen using it. | ||
- show-background? : blurred container that is activated when this component is on top of the page content. | ||
- keyboard-shown? : keyboard is visible on the current page. | ||
" | ||
(defn get-margin-bottom | ||
[show-background? keyboard-shown?] | ||
(cond keyboard-shown? (safe-area/get-top) | ||
(and show-background? keyboard-shown?) (safe-area/get-bottom) | ||
:else (safe-area/get-bottom))) | ||
|
||
(defn f-view | ||
[{:keys [on-layout theme show-background? keyboard-shown?]} | ||
children] | ||
(let [blur-active? show-background? | ||
container-view (if blur-active? blur-container rn/view) | ||
inline-container-style (if blur-active? style/blur-container style/view-container) | ||
margin-bottom (reanimated/use-shared-value (get-margin-bottom show-background? | ||
keyboard-shown?))] | ||
(rn/use-effect #(reanimated/animate-shared-value-with-timing | ||
margin-bottom | ||
(get-margin-bottom show-background? keyboard-shown?) | ||
duration | ||
:easing4) | ||
[show-background? keyboard-shown?]) | ||
[reanimated/view | ||
{:style (reanimated/apply-animations-to-style | ||
{:margin-bottom margin-bottom} | ||
{:margin-top :auto})} | ||
[container-view | ||
{:on-layout on-layout | ||
:theme theme | ||
:style | ||
(merge inline-container-style)} | ||
children]])) | ||
|
||
(defn view | ||
[props children] | ||
[:f> f-view props children]) |
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,114 @@ | ||
(ns status-im2.common.floating-button-page.view | ||
(:require | ||
[oops.core :as oops] | ||
[quo.theme :as quo.theme] | ||
[react-native.core :as rn] | ||
[react-native.hooks :as hooks] | ||
[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-android | ||
[{:keys [window-height keyboard-height floating-container-height | ||
content-scroll-y content-container-height header-height]} keyboard-shown?] | ||
(let [available-space (- window-height | ||
keyboard-height | ||
floating-container-height | ||
(safe-area/get-top) | ||
(safe-area/get-bottom)) | ||
content-height (+ content-scroll-y | ||
content-container-height | ||
header-height)] | ||
(and keyboard-shown? (< available-space content-height)))) | ||
|
||
(defn- show-background-ios | ||
[{:keys [window-height keyboard-height floating-container-height | ||
content-scroll-y content-container-height header-height]} keyboard-shown?] | ||
(let [available-space (- window-height | ||
keyboard-height | ||
floating-container-height | ||
(safe-area/get-top)) | ||
content-height (+ (safe-area/get-bottom) | ||
header-height | ||
content-scroll-y | ||
content-container-height)] | ||
(and keyboard-shown? (< content-height available-space)))) | ||
|
||
(defn show-background | ||
[props keyboard-shown?] | ||
(if platform/android? | ||
(show-background-android props keyboard-shown?) | ||
(show-background-ios props keyboard-shown?))) | ||
|
||
(defn f-view | ||
[{:keys [header footer]} | ||
page-content] | ||
(reagent/with-let [theme (quo.theme/use-theme-value) | ||
window-height (:height (rn/get-window)) | ||
|
||
floating-container-height (reagent/atom 0) | ||
header-height (reagent/atom 0) | ||
content-container-height (reagent/atom 0) | ||
show-keyboard? (reagent/atom false) | ||
content-scroll-y (reagent/atom 0) | ||
|
||
show-listener (oops/ocall rn/keyboard | ||
"addListener" | ||
(if platform/android? | ||
"keyboardDidShow" | ||
"keyboardWillShow") | ||
#(reset! show-keyboard? true)) | ||
hide-listener (oops/ocall rn/keyboard | ||
"addListener" | ||
(if platform/android? | ||
"keyboardDidHide" | ||
"keyboardWillHide") | ||
#(reset! show-keyboard? false))] | ||
(let [{:keys [keyboard-shown | ||
keyboard-height]} (hooks/use-keyboard) | ||
show-background? (show-background {:window-height window-height | ||
:floating-container-height | ||
@floating-container-height | ||
:keyboard-height keyboard-height | ||
:content-scroll-y @content-scroll-y | ||
:content-container-height @content-container-height | ||
:header-height @header-height} | ||
keyboard-shown)] | ||
|
||
[rn/view {:style style/page-container} | ||
[rn/view | ||
{:on-layout (fn [event] | ||
(let [height (oops/oget event "nativeEvent.layout.height")] | ||
(reset! header-height height)))} | ||
header] | ||
[rn/scroll-view | ||
{:on-scroll (fn [event] | ||
(let [y (oops/oget event "nativeEvent.contentOffset.y")] | ||
(reset! content-scroll-y y))) | ||
:scroll-event-throttle 64 | ||
:content-container-style {:flexGrow 1}} | ||
[rn/view | ||
{:on-layout (fn [event] | ||
(let [height (oops/oget event "nativeEvent.layout.height")] | ||
(reset! content-container-height height)))} | ||
page-content]] | ||
[rn/keyboard-avoiding-view | ||
{:style style/keyboard-avoiding-view | ||
:pointer-events :box-none} | ||
[floating-container/view | ||
{:theme theme | ||
:keyboard-shown? keyboard-shown | ||
:show-background? show-background? | ||
:on-layout (fn [event] | ||
(let [height (oops/oget event "nativeEvent.layout.height")] | ||
(reset! floating-container-height height)))} | ||
footer]]]) | ||
(finally | ||
(oops/ocall show-listener "remove") | ||
(oops/ocall hide-listener "remove")))) | ||
|
||
(defn view | ||
[props header page-content button-component] | ||
[:f> f-view props header page-content button-component]) |
Oops, something went wrong.