[#16073] Password info box

* Refactor: Remove use of f-component

* Fix documentation drawer styles

* Refactor: move title styles to style ns

* Fix StaticSafeAreaInsets not being defined on component tests

* Fix bottom sheet height on Android
This commit is contained in:
Ulises Manuel Cárdenas 2023-07-04 17:08:47 -06:00 committed by GitHub
parent ca0915c940
commit e260187cf5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 62 additions and 61 deletions

View File

@ -1,4 +1,10 @@
(ns quo2.components.drawers.documentation-drawers.style) (ns quo2.components.drawers.documentation-drawers.style
(:require [quo2.foundations.colors :as colors]
[react-native.safe-area :as safe-area]))
(def outer-container
;; Margin negative to fill the bottom-sheet container where this component is used
{:margin-bottom (- (+ (safe-area/get-bottom) 8))})
(def container (def container
{:align-items :flex-start {:align-items :flex-start
@ -6,4 +12,10 @@
(def content (def content
{:margin-top 8 {:margin-top 8
:margin-bottom 16}) :margin-bottom (+ (safe-area/get-bottom) 8)})
(defn title
[shell?]
{:color (colors/theme-colors colors/neutral-100
colors/white
(when shell? :dark))})

View File

@ -1,10 +1,9 @@
(ns quo2.components.drawers.documentation-drawers.view (ns quo2.components.drawers.documentation-drawers.view
(:require [quo2.components.markdown.text :as text] (:require [quo2.components.buttons.button :as button]
[quo2.components.drawers.documentation-drawers.style :as style] [quo2.components.drawers.documentation-drawers.style :as style]
[quo2.components.markdown.text :as text]
[react-native.core :as rn] [react-native.core :as rn]
[react-native.gesture :as gesture] [react-native.gesture :as gesture]))
[quo2.components.buttons.button :as button]
[quo2.foundations.colors :as colors]))
(defn view (defn view
"Options "Options
@ -14,18 +13,18 @@
- `button-icon` button icon - `button-icon` button icon
- `on-press-button` On press handler for the button - `on-press-button` On press handler for the button
- `shell?` use shell theme - `shell?` use shell theme
`content` Content of the drawer `content` Content of the drawer
" "
[{:keys [title show-button? on-press-button button-label button-icon shell?]} content] [{:keys [title show-button? on-press-button button-label button-icon shell?]} content]
[gesture/scroll-view [gesture/scroll-view
{:style style/outer-container
:always-bounce-vertical false
:content-inset-adjustment-behavior :never}
[rn/view {:style style/container} [rn/view {:style style/container}
[text/text [text/text
{:size :heading-2 {:size :heading-2
:accessibility-label :documentation-drawer-title :accessibility-label :documentation-drawer-title
:style {:color (colors/theme-colors colors/neutral-100 :style (style/title shell?)
colors/white
(when shell? :dark))}
:weight :semi-bold} :weight :semi-bold}
title] title]
[rn/view {:style style/content :accessibility-label :documentation-drawer-content} [rn/view {:style style/content :accessibility-label :documentation-drawer-content}

View File

@ -10,7 +10,8 @@
(defn- get-static-bottom (defn- get-static-bottom
[] []
(oops/oget StaticSafeAreaInsets "safeAreaInsetsBottom")) (some-> StaticSafeAreaInsets
(oops/oget "safeAreaInsetsBottom")))
(defn get-top (defn get-top
[] []
@ -20,8 +21,8 @@
(defn get-bottom (defn get-bottom
[] []
(if platform/ios? (if-let [bottom (and platform/ios? (get-static-bottom))]
(get-static-bottom) bottom
0)) 0))
(defn get-insets (defn get-insets

View File

@ -16,8 +16,7 @@
(defn sheet (defn sheet
[{:keys [top bottom]} window-height override-theme padding-bottom-override shell?] [{:keys [top bottom]} window-height override-theme padding-bottom-override shell?]
{:position :absolute {:position :absolute
:max-height (cond-> window-height :max-height (- window-height top)
platform/ios? (- top))
:z-index 1 :z-index 1
:bottom 0 :bottom 0
:left 0 :left 0

View File

@ -187,54 +187,44 @@
(defn create-password-doc (defn create-password-doc
[] []
[quo/documentation-drawers [quo/documentation-drawers
{:title (i18n/label {:title (i18n/label :t/create-profile-password-info-box-title)
:t/create-profile-password-info-box-title)
:shell? true} :shell? true}
[rn/view [rn/view
[quo/text [quo/text {:size :paragraph-2}
{:size :paragraph-2} (i18n/label :t/create-profile-password-info-box-description)]]])
(i18n/label
:t/create-profile-password-info-box-description)]]])
(defn- f-create-password
[]
(let [keyboard-shown? (reagent/atom false)
{:keys [top bottom]} (safe-area/get-insets)]
(fn []
(rn/use-effect
(let [will-show-listener (ocall rn/keyboard
"addListener"
"keyboardWillShow"
#(reset! keyboard-shown? true))
will-hide-listener (ocall rn/keyboard
"addListener"
"keyboardWillHide"
#(reset! keyboard-shown? false))]
(fn []
(fn []
(ocall will-show-listener "remove")
(ocall will-hide-listener "remove"))))
[])
[rn/touchable-without-feedback
{:on-press rn/dismiss-keyboard!
:accessible false}
[rn/view {:style style/flex-fill}
[rn/keyboard-avoiding-view {:style style/flex-fill}
[navigation-bar/navigation-bar
{:top top
:right-section-buttons [{:type :blur-bg
:icon :i/info
:icon-override-theme :dark
:on-press (fn []
(rn/dismiss-keyboard!)
(rf/dispatch [:show-bottom-sheet
{:content create-password-doc
:shell? true}]))}]}]
[password-form]
[rn/view {:style {:height (if-not @keyboard-shown? bottom 0)}}]]]])))
(defn create-password (defn create-password
[] []
[:<> (reagent/with-let [keyboard-shown? (reagent/atom false)
[background/view true] {:keys [top bottom]} (safe-area/get-insets)
[:f> f-create-password]]) will-show-listener (ocall rn/keyboard
"addListener"
"keyboardWillShow"
#(reset! keyboard-shown? true))
will-hide-listener (ocall rn/keyboard
"addListener"
"keyboardWillHide"
#(reset! keyboard-shown? false))
on-press-info (fn []
(rn/dismiss-keyboard!)
(rf/dispatch [:show-bottom-sheet
{:content create-password-doc
:shell? true}]))]
[:<>
[background/view true]
[rn/touchable-without-feedback
{:on-press rn/dismiss-keyboard!
:accessible false}
[rn/view {:style style/flex-fill}
[rn/keyboard-avoiding-view {:style style/flex-fill}
[navigation-bar/navigation-bar
{:top top
:right-section-buttons [{:type :blur-bg
:icon :i/info
:icon-override-theme :dark
:on-press on-press-info}]}]
[password-form]
[rn/view {:style {:height (if-not @keyboard-shown? bottom 0)}}]]]]]
(finally
(ocall will-show-listener "remove")
(ocall will-hide-listener "remove"))))