Enable functional components by default (#18820)

* enable functional components by default

* e2e: updated counter component locator

---------

Co-authored-by: Yevheniia Berdnyk <ie.berdnyk@gmail.com>
This commit is contained in:
flexsurfer 2024-02-23 18:29:10 +01:00 committed by GitHub
parent 265b712fe3
commit 3c4f72c061
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
18 changed files with 81 additions and 89 deletions

View File

@ -16,12 +16,14 @@
:align-self :center}) :align-self :center})
(def backdrop (def backdrop
{:position :absolute {:position :absolute
:left 0 :left 0
:right 0 :right 0
:bottom 0 :bottom 0
:top 0 :top 0})
:background-color colors/neutral-100})
(def backdrop-color
{:background-color colors/neutral-100})
(def container (def container
{:position :absolute {:position :absolute

View File

@ -207,11 +207,13 @@
[@show-bottom-sheet? @expanded? @gesture-running?]) [@show-bottom-sheet? @expanded? @gesture-running?])
[:<> [:<>
[rn/touchable-without-feedback {:on-press (when backdrop-dismiss? close-bottom-sheet)} [rn/pressable
{:on-press (when backdrop-dismiss? close-bottom-sheet)
:style styles/backdrop}
[reanimated/view [reanimated/view
{:style (reanimated/apply-animations-to-style {:style (reanimated/apply-animations-to-style
{:opacity bg-opacity} {:opacity bg-opacity}
styles/backdrop)}]] styles/backdrop-color)}]]
(cond->> [reanimated/view (cond->> [reanimated/view
{:style (reanimated/apply-animations-to-style {:style (reanimated/apply-animations-to-style
{:transform [{:translateY translate-y}]} {:transform [{:translateY translate-y}]}

View File

@ -1,13 +1,12 @@
(ns legacy.status-im.ui.components.keyboard-avoid-presentation (ns legacy.status-im.ui.components.keyboard-avoid-presentation
(:require (:require
[legacy.status-im.ui.components.react :as react] [legacy.status-im.ui.components.react :as react]
[react-native.utils :as rn.utils]
[reagent.core :as reagent])) [reagent.core :as reagent]))
(defn keyboard-avoiding-view (defn keyboard-avoiding-view
[] [& argv]
(let [this (reagent/current-component) (let [[props children] (rn.utils/get-props-and-children argv)]
props (reagent/props this)
children (reagent/children this)]
(reagent/as-element (reagent/as-element
(into [react/keyboard-avoiding-view (into [react/keyboard-avoiding-view
(update props (update props

View File

@ -3,16 +3,16 @@
[legacy.status-im.ui.components.spacing :as spacing] [legacy.status-im.ui.components.spacing :as spacing]
[legacy.status-im.ui.components.text :as text] [legacy.status-im.ui.components.text :as text]
[react-native.core :as rn] [react-native.core :as rn]
[reagent.core :as reagent])) [react-native.utils :as rn.utils]))
(defn footer (defn footer
[] [& argv]
(let [this (reagent/current-component) (let [[props children] (rn.utils/get-props-and-children argv)
{:keys [color] {:keys [color]
:or {color :secondary}} :or {color :secondary}}
(reagent/props this)] props]
[rn/view [rn/view
{:style (merge (:base spacing/padding-horizontal) {:style (merge (:base spacing/padding-horizontal)
(:small spacing/padding-vertical))} (:small spacing/padding-vertical))}
(into [text/text {:color color}] (into [text/text {:color color}]
(reagent/children this))])) children)]))

View File

@ -3,18 +3,18 @@
[legacy.status-im.ui.components.spacing :as spacing] [legacy.status-im.ui.components.spacing :as spacing]
[legacy.status-im.ui.components.text :as text] [legacy.status-im.ui.components.text :as text]
[react-native.core :as rn] [react-native.core :as rn]
[reagent.core :as reagent])) [react-native.utils :as rn.utils]))
(defn header (defn header
[] [& argv]
(let [this (reagent/current-component) (let [[props children] (rn.utils/get-props-and-children argv)
{:keys [color] {:keys [color]
:or {color :secondary}} :or {color :secondary}}
(reagent/props this)] props]
[rn/view [rn/view
{:style (merge (:base spacing/padding-horizontal) {:style (merge (:base spacing/padding-horizontal)
(:x-tiny spacing/padding-vertical))} (:x-tiny spacing/padding-vertical))}
(into [text/text (into [text/text
{:color color {:color color
:style {:margin-top 10}}] :style {:margin-top 10}}]
(reagent/children this))])) children)]))

View File

@ -3,7 +3,7 @@
[legacy.status-im.ui.components.colors :as colors] [legacy.status-im.ui.components.colors :as colors]
[legacy.status-im.ui.components.typography :as typography] [legacy.status-im.ui.components.typography :as typography]
[react-native.core :as rn] [react-native.core :as rn]
[reagent.core :as reagent])) [react-native.utils :as rn.utils]))
(defn text-style (defn text-style
[{:keys [size align weight monospace color style]}] [{:keys [size align weight monospace color style]}]
@ -40,11 +40,9 @@
style)) style))
(defn text (defn text
[] [& argv]
(let [this (reagent/current-component) (let [[props children] (rn.utils/get-props-and-children argv)]
props (reagent/props this) (into [rn/text
component rn/text]
(into [component
(merge {:style (text-style props)} (merge {:style (text-style props)}
(dissoc props (dissoc props
:style :style
@ -53,4 +51,4 @@
:color :color
:align :align
:animated?))] :animated?))]
(reagent/children this)))) children)))

View File

@ -5,35 +5,32 @@
[react-native.platform :as platform] [react-native.platform :as platform]
[reagent.core :as reagent])) [reagent.core :as reagent]))
(def cached-sources (js/Set. (js/Array.))) (def cached-sources (js/Set. (js/Array.)))
(defn- caching-image (defn- caching-image
[_ on-source-loaded] [{:keys [source]} on-source-loaded]
(let [this (reagent/current-component)] (reagent/create-class
(reagent/create-class {:component-did-update
{:component-did-update (fn []
(fn [] (when (oops/ocall cached-sources "has" source)
(let [source (-> this reagent/props :source)] (on-source-loaded source)))
(when (oops/ocall cached-sources "has" source) :reagent-render
(on-source-loaded source)))) (fn [{:keys [source] :as props}]
:reagent-render [rn/image
(fn [{:keys [source] :as props}] (assoc props
[rn/image ;; hide the cache image under the real one
(assoc props ;; have to render it for the on-load event
;; hide the cache image under the real one :style {:width 1
;; have to render it for the on-load event :height 1
:style {:width 1 :left "50%"
:height 1 :top "50%"
:left "50%" :position :absolute}
:top "50%" :on-load
:position :absolute} (fn [_]
:on-load (when-not (oops/ocall cached-sources "has" source)
(fn [_] (oops/ocall cached-sources "add" source)
(when-not (oops/ocall cached-sources "has" source) (on-source-loaded source)))
(oops/ocall cached-sources "add" source) :on-error js/console.error)])}))
(on-source-loaded source)))
:on-error js/console.error)])})))
(defn image (defn image
"Same as rn/image but cache the image source in a js/Set, so the image won't "Same as rn/image but cache the image source in a js/Set, so the image won't

View File

@ -4,7 +4,7 @@
[quo.foundations.typography :as typography] [quo.foundations.typography :as typography]
[quo.theme :as quo.theme] [quo.theme :as quo.theme]
[react-native.core :as rn] [react-native.core :as rn]
[reagent.core :as reagent])) [react-native.utils :as rn.utils]))
(defn text-style (defn text-style
[{:keys [size align weight style theme]}] [{:keys [size align weight style theme]}]
@ -41,8 +41,6 @@
(def ^:private text-view (quo.theme/with-theme text-view-internal)) (def ^:private text-view (quo.theme/with-theme text-view-internal))
(defn text (defn text
[] [& argv]
(let [this (reagent/current-component) (let [[props children] (rn.utils/get-props-and-children argv)]
props (reagent/props this)
children (reagent/children this)]
(into [text-view props] children))) (into [text-view props] children)))

View File

@ -46,7 +46,7 @@
{:width 90 {:width 90
:height 40 :height 40
:border-radius 10})] :border-radius 10})]
[rn/touchable-without-feedback [rn/pressable
{:test-ID test-ID {:test-ID test-ID
:allow-multiple-presses? true :allow-multiple-presses? true
:on-press on-press :on-press on-press

View File

@ -42,7 +42,7 @@
[0 total-amount] [0 total-amount]
[0 total-width]) [0 total-width])
width->amount #(/ (* % total-amount) total-width)] width->amount #(/ (* % total-amount) total-width)]
[rn/touchable-without-feedback [rn/pressable
{:on-press (fn [] {:on-press (fn []
(when (and (not @detecting-gesture?) allow-press?) (when (and (not @detecting-gesture?) allow-press?)
(on-press) (on-press)

View File

@ -53,8 +53,9 @@
(into [touchable-highlight-class (utils/custom-pressable-props props)] children)) (into [touchable-highlight-class (utils/custom-pressable-props props)] children))
(defn touchable-without-feedback (defn touchable-without-feedback
[props & children] {:deprecated "pressable should be used instead"}
(into [touchable-without-feedback-class (utils/custom-pressable-props props)] children)) [props child]
[touchable-without-feedback-class (utils/custom-pressable-props props) child])
(def flat-list flat-list/flat-list) (def flat-list flat-list/flat-list)

View File

@ -22,8 +22,8 @@
useAnimatedScrollHandler useAnimatedScrollHandler
runOnJS)] runOnJS)]
["react-native-redash" :refer (withPause)] ["react-native-redash" :refer (withPause)]
[oops.core :as oops]
[react-native.flat-list :as rn-flat-list] [react-native.flat-list :as rn-flat-list]
[react-native.utils :as rn.utils]
[reagent.core :as reagent] [reagent.core :as reagent]
[utils.transforms :as transforms] [utils.transforms :as transforms]
[utils.worklets.core :as worklets.core])) [utils.worklets.core :as worklets.core]))
@ -43,16 +43,10 @@
(def ^:private view* (reagent/adapt-react-class (.-View reanimated))) (def ^:private view* (reagent/adapt-react-class (.-View reanimated)))
(defn view (defn view
[] [& argv]
(let [current-component (reagent/current-component) (let [[reagent-props children] (rn.utils/get-props-and-children argv)
reagent-props (reagent/props current-component) updated-props (update reagent-props :style transforms/styles-with-vectors)]
children (reagent/children current-component) (into [view* updated-props] children)))
updated-props (update reagent-props :style transforms/styles-with-vectors)
;; Some components add JS props to their children (such as TouchableWithoutFeedback), to make
;; this component fully compatible we are passing those props to the inner component (`view*`).
external-props (oops/gobj-get current-component "props")
all-props (transforms/copy-js-obj-to-map external-props updated-props #(not= % "argv"))]
(into [view* all-props] children)))
(def text (reagent/adapt-react-class (.-Text reanimated))) (def text (reagent/adapt-react-class (.-Text reanimated)))
(def scroll-view (reagent/adapt-react-class (.-ScrollView reanimated))) (def scroll-view (reagent/adapt-react-class (.-ScrollView reanimated)))

View File

@ -30,3 +30,10 @@
on-press on-press
(assoc :on-press (throttled-on-press props throttle-id) (assoc :on-press (throttled-on-press props throttle-id)
:ref (wrapped-ref props throttle-id))))) :ref (wrapped-ref props throttle-id)))))
(defn get-props-and-children
[argv]
(let [first-child (first argv)
props (when (map? first-child) first-child)
children (if props (rest argv) argv)]
[props children]))

View File

@ -94,7 +94,9 @@
true)) true))
[rn/view {:style {:flex 1}} [rn/view {:style {:flex 1}}
;; backdrop ;; backdrop
[rn/touchable-without-feedback {:on-press #(rf/dispatch [:hide-bottom-sheet])} [rn/pressable
{:on-press #(rf/dispatch [:hide-bottom-sheet])
:style {:flex 1}}
[reanimated/view [reanimated/view
{:style (reanimated/apply-animations-to-style {:style (reanimated/apply-animations-to-style
{:opacity bg-opacity} {:opacity bg-opacity}

View File

@ -203,7 +203,7 @@
(defn- f-bottom-view (defn- f-bottom-view
[insets translate-y] [insets translate-y]
[rn/touchable-without-feedback [rn/pressable
{:on-press #(js/alert "Yet to be implemented")} {:on-press #(js/alert "Yet to be implemented")}
[reanimated/view [reanimated/view
{:style (style/bottom-container translate-y (:bottom insets))} {:style (style/bottom-container translate-y (:bottom insets))}

View File

@ -12,6 +12,7 @@
[react-native.core :as rn] [react-native.core :as rn]
[react-native.platform :as platform] [react-native.platform :as platform]
[react-native.shake :as react-native-shake] [react-native.shake :as react-native-shake]
[reagent.core]
[reagent.impl.batching :as batching] [reagent.impl.batching :as batching]
[status-im.common.log :as logging] [status-im.common.log :as logging]
[taoensso.timbre :as log] [taoensso.timbre :as log]
@ -32,6 +33,8 @@
;;;; re-frame RN setup ;;;; re-frame RN setup
(set! interop/next-tick js/setTimeout) (set! interop/next-tick js/setTimeout)
(set! batching/fake-raf #(js/setTimeout % 0)) (set! batching/fake-raf #(js/setTimeout % 0))
(def functional-compiler (reagent.core/create-compiler {:function-components true}))
(reagent.core/set-default-compiler! functional-compiler)
(def adjust-resize 16) (def adjust-resize 16)

View File

@ -49,14 +49,3 @@
(map? x) (reduce-kv convert-keys-and-values #js {} x) (map? x) (reduce-kv convert-keys-and-values #js {} x)
(vector? x) (to-array (mapv styles-with-vectors x)) (vector? x) (to-array (mapv styles-with-vectors x))
:else (clj->js x))) :else (clj->js x)))
(defn copy-js-obj-to-map
"Copy `obj` keys and values into `m` if `(pred obj-key)` is satisfied."
[obj m pred]
(persistent!
(reduce (fn [acc js-prop]
(if (pred js-prop)
(assoc! acc js-prop (oops/gobj-get obj js-prop))
acc))
(transient m)
(js-keys obj))))

View File

@ -41,7 +41,7 @@ class AllowButton(Button):
class UnreadMessagesCountText(Text): class UnreadMessagesCountText(Text):
def __init__(self, driver, parent_locator: str): def __init__(self, driver, parent_locator: str):
super().__init__(driver, super().__init__(driver,
xpath="%s/*[@resource-id='counter-component']/android.widget.TextView" % parent_locator) xpath="%s//*[@resource-id='counter-component']/android.widget.TextView" % parent_locator)
class TabButton(Button): class TabButton(Button):