Skip to content

Commit 3c4f72c

Browse files
Enable functional components by default (#18820)
* enable functional components by default * e2e: updated counter component locator --------- Co-authored-by: Yevheniia Berdnyk <[email protected]>
1 parent 265b712 commit 3c4f72c

File tree

18 files changed

+81
-89
lines changed

18 files changed

+81
-89
lines changed

src/legacy/status_im/bottom_sheet/styles.cljs

+8-6
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,14 @@
1616
:align-self :center})
1717

1818
(def backdrop
19-
{:position :absolute
20-
:left 0
21-
:right 0
22-
:bottom 0
23-
:top 0
24-
:background-color colors/neutral-100})
19+
{:position :absolute
20+
:left 0
21+
:right 0
22+
:bottom 0
23+
:top 0})
24+
25+
(def backdrop-color
26+
{:background-color colors/neutral-100})
2527

2628
(def container
2729
{:position :absolute

src/legacy/status_im/bottom_sheet/view.cljs

+4-2
Original file line numberDiff line numberDiff line change
@@ -207,11 +207,13 @@
207207
[@show-bottom-sheet? @expanded? @gesture-running?])
208208

209209
[:<>
210-
[rn/touchable-without-feedback {:on-press (when backdrop-dismiss? close-bottom-sheet)}
210+
[rn/pressable
211+
{:on-press (when backdrop-dismiss? close-bottom-sheet)
212+
:style styles/backdrop}
211213
[reanimated/view
212214
{:style (reanimated/apply-animations-to-style
213215
{:opacity bg-opacity}
214-
styles/backdrop)}]]
216+
styles/backdrop-color)}]]
215217
(cond->> [reanimated/view
216218
{:style (reanimated/apply-animations-to-style
217219
{:transform [{:translateY translate-y}]}

src/legacy/status_im/ui/components/keyboard_avoid_presentation.cljs

+3-4
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
11
(ns legacy.status-im.ui.components.keyboard-avoid-presentation
22
(:require
33
[legacy.status-im.ui.components.react :as react]
4+
[react-native.utils :as rn.utils]
45
[reagent.core :as reagent]))
56

67
(defn keyboard-avoiding-view
7-
[]
8-
(let [this (reagent/current-component)
9-
props (reagent/props this)
10-
children (reagent/children this)]
8+
[& argv]
9+
(let [[props children] (rn.utils/get-props-and-children argv)]
1110
(reagent/as-element
1211
(into [react/keyboard-avoiding-view
1312
(update props

src/legacy/status_im/ui/components/list/footer.cljs

+5-5
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,16 @@
33
[legacy.status-im.ui.components.spacing :as spacing]
44
[legacy.status-im.ui.components.text :as text]
55
[react-native.core :as rn]
6-
[reagent.core :as reagent]))
6+
[react-native.utils :as rn.utils]))
77

88
(defn footer
9-
[]
10-
(let [this (reagent/current-component)
9+
[& argv]
10+
(let [[props children] (rn.utils/get-props-and-children argv)
1111
{:keys [color]
1212
:or {color :secondary}}
13-
(reagent/props this)]
13+
props]
1414
[rn/view
1515
{:style (merge (:base spacing/padding-horizontal)
1616
(:small spacing/padding-vertical))}
1717
(into [text/text {:color color}]
18-
(reagent/children this))]))
18+
children)]))

src/legacy/status_im/ui/components/list/header.cljs

+5-5
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,18 @@
33
[legacy.status-im.ui.components.spacing :as spacing]
44
[legacy.status-im.ui.components.text :as text]
55
[react-native.core :as rn]
6-
[reagent.core :as reagent]))
6+
[react-native.utils :as rn.utils]))
77

88
(defn header
9-
[]
10-
(let [this (reagent/current-component)
9+
[& argv]
10+
(let [[props children] (rn.utils/get-props-and-children argv)
1111
{:keys [color]
1212
:or {color :secondary}}
13-
(reagent/props this)]
13+
props]
1414
[rn/view
1515
{:style (merge (:base spacing/padding-horizontal)
1616
(:x-tiny spacing/padding-vertical))}
1717
(into [text/text
1818
{:color color
1919
:style {:margin-top 10}}]
20-
(reagent/children this))]))
20+
children)]))

src/legacy/status_im/ui/components/text.cljs

+5-7
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
[legacy.status-im.ui.components.colors :as colors]
44
[legacy.status-im.ui.components.typography :as typography]
55
[react-native.core :as rn]
6-
[reagent.core :as reagent]))
6+
[react-native.utils :as rn.utils]))
77

88
(defn text-style
99
[{:keys [size align weight monospace color style]}]
@@ -40,11 +40,9 @@
4040
style))
4141

4242
(defn text
43-
[]
44-
(let [this (reagent/current-component)
45-
props (reagent/props this)
46-
component rn/text]
47-
(into [component
43+
[& argv]
44+
(let [[props children] (rn.utils/get-props-and-children argv)]
45+
(into [rn/text
4846
(merge {:style (text-style props)}
4947
(dissoc props
5048
:style
@@ -53,4 +51,4 @@
5351
:color
5452
:align
5553
:animated?))]
56-
(reagent/children this))))
54+
children)))

src/quo/components/common/no_flicker_image.cljs

+23-26
Original file line numberDiff line numberDiff line change
@@ -5,35 +5,32 @@
55
[react-native.platform :as platform]
66
[reagent.core :as reagent]))
77

8-
98
(def cached-sources (js/Set. (js/Array.)))
109

1110
(defn- caching-image
12-
[_ on-source-loaded]
13-
(let [this (reagent/current-component)]
14-
(reagent/create-class
15-
{:component-did-update
16-
(fn []
17-
(let [source (-> this reagent/props :source)]
18-
(when (oops/ocall cached-sources "has" source)
19-
(on-source-loaded source))))
20-
:reagent-render
21-
(fn [{:keys [source] :as props}]
22-
[rn/image
23-
(assoc props
24-
;; hide the cache image under the real one
25-
;; have to render it for the on-load event
26-
:style {:width 1
27-
:height 1
28-
:left "50%"
29-
:top "50%"
30-
:position :absolute}
31-
:on-load
32-
(fn [_]
33-
(when-not (oops/ocall cached-sources "has" source)
34-
(oops/ocall cached-sources "add" source)
35-
(on-source-loaded source)))
36-
:on-error js/console.error)])})))
11+
[{:keys [source]} on-source-loaded]
12+
(reagent/create-class
13+
{:component-did-update
14+
(fn []
15+
(when (oops/ocall cached-sources "has" source)
16+
(on-source-loaded source)))
17+
:reagent-render
18+
(fn [{:keys [source] :as props}]
19+
[rn/image
20+
(assoc props
21+
;; hide the cache image under the real one
22+
;; have to render it for the on-load event
23+
:style {:width 1
24+
:height 1
25+
:left "50%"
26+
:top "50%"
27+
:position :absolute}
28+
:on-load
29+
(fn [_]
30+
(when-not (oops/ocall cached-sources "has" source)
31+
(oops/ocall cached-sources "add" source)
32+
(on-source-loaded source)))
33+
:on-error js/console.error)])}))
3734

3835
(defn image
3936
"Same as rn/image but cache the image source in a js/Set, so the image won't

src/quo/components/markdown/text.cljs

+3-5
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
[quo.foundations.typography :as typography]
55
[quo.theme :as quo.theme]
66
[react-native.core :as rn]
7-
[reagent.core :as reagent]))
7+
[react-native.utils :as rn.utils]))
88

99
(defn text-style
1010
[{:keys [size align weight style theme]}]
@@ -41,8 +41,6 @@
4141
(def ^:private text-view (quo.theme/with-theme text-view-internal))
4242

4343
(defn text
44-
[]
45-
(let [this (reagent/current-component)
46-
props (reagent/props this)
47-
children (reagent/children this)]
44+
[& argv]
45+
(let [[props children] (rn.utils/get-props-and-children argv)]
4846
(into [text-view props] children)))

src/quo/components/navigation/bottom_nav_tab/view.cljs

+1-1
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@
4646
{:width 90
4747
:height 40
4848
:border-radius 10})]
49-
[rn/touchable-without-feedback
49+
[rn/pressable
5050
{:test-ID test-ID
5151
:allow-multiple-presses? true
5252
:on-press on-press

src/quo/components/wallet/network_routing/view.cljs

+1-1
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242
[0 total-amount]
4343
[0 total-width])
4444
width->amount #(/ (* % total-amount) total-width)]
45-
[rn/touchable-without-feedback
45+
[rn/pressable
4646
{:on-press (fn []
4747
(when (and (not @detecting-gesture?) allow-press?)
4848
(on-press)

src/react_native/core.cljs

+3-2
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,9 @@
5353
(into [touchable-highlight-class (utils/custom-pressable-props props)] children))
5454

5555
(defn touchable-without-feedback
56-
[props & children]
57-
(into [touchable-without-feedback-class (utils/custom-pressable-props props)] children))
56+
{:deprecated "pressable should be used instead"}
57+
[props child]
58+
[touchable-without-feedback-class (utils/custom-pressable-props props) child])
5859

5960
(def flat-list flat-list/flat-list)
6061

src/react_native/reanimated.cljs

+5-11
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@
2222
useAnimatedScrollHandler
2323
runOnJS)]
2424
["react-native-redash" :refer (withPause)]
25-
[oops.core :as oops]
2625
[react-native.flat-list :as rn-flat-list]
26+
[react-native.utils :as rn.utils]
2727
[reagent.core :as reagent]
2828
[utils.transforms :as transforms]
2929
[utils.worklets.core :as worklets.core]))
@@ -43,16 +43,10 @@
4343
(def ^:private view* (reagent/adapt-react-class (.-View reanimated)))
4444

4545
(defn view
46-
[]
47-
(let [current-component (reagent/current-component)
48-
reagent-props (reagent/props current-component)
49-
children (reagent/children current-component)
50-
updated-props (update reagent-props :style transforms/styles-with-vectors)
51-
;; Some components add JS props to their children (such as TouchableWithoutFeedback), to make
52-
;; this component fully compatible we are passing those props to the inner component (`view*`).
53-
external-props (oops/gobj-get current-component "props")
54-
all-props (transforms/copy-js-obj-to-map external-props updated-props #(not= % "argv"))]
55-
(into [view* all-props] children)))
46+
[& argv]
47+
(let [[reagent-props children] (rn.utils/get-props-and-children argv)
48+
updated-props (update reagent-props :style transforms/styles-with-vectors)]
49+
(into [view* updated-props] children)))
5650

5751
(def text (reagent/adapt-react-class (.-Text reanimated)))
5852
(def scroll-view (reagent/adapt-react-class (.-ScrollView reanimated)))

src/react_native/utils.cljs

+7
Original file line numberDiff line numberDiff line change
@@ -30,3 +30,10 @@
3030
on-press
3131
(assoc :on-press (throttled-on-press props throttle-id)
3232
:ref (wrapped-ref props throttle-id)))))
33+
34+
(defn get-props-and-children
35+
[argv]
36+
(let [first-child (first argv)
37+
props (when (map? first-child) first-child)
38+
children (if props (rest argv) argv)]
39+
[props children]))

src/status_im/common/bottom_sheet/view.cljs

+3-1
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,9 @@
9494
true))
9595
[rn/view {:style {:flex 1}}
9696
;; backdrop
97-
[rn/touchable-without-feedback {:on-press #(rf/dispatch [:hide-bottom-sheet])}
97+
[rn/pressable
98+
{:on-press #(rf/dispatch [:hide-bottom-sheet])
99+
:style {:flex 1}}
98100
[reanimated/view
99101
{:style (reanimated/apply-animations-to-style
100102
{:opacity bg-opacity}

src/status_im/contexts/syncing/scan_sync_code/view.cljs

+1-1
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@
203203

204204
(defn- f-bottom-view
205205
[insets translate-y]
206-
[rn/touchable-without-feedback
206+
[rn/pressable
207207
{:on-press #(js/alert "Yet to be implemented")}
208208
[reanimated/view
209209
{:style (style/bottom-container translate-y (:bottom insets))}

src/status_im/core.cljs

+3
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
[react-native.core :as rn]
1313
[react-native.platform :as platform]
1414
[react-native.shake :as react-native-shake]
15+
[reagent.core]
1516
[reagent.impl.batching :as batching]
1617
[status-im.common.log :as logging]
1718
[taoensso.timbre :as log]
@@ -32,6 +33,8 @@
3233
;;;; re-frame RN setup
3334
(set! interop/next-tick js/setTimeout)
3435
(set! batching/fake-raf #(js/setTimeout % 0))
36+
(def functional-compiler (reagent.core/create-compiler {:function-components true}))
37+
(reagent.core/set-default-compiler! functional-compiler)
3538

3639
(def adjust-resize 16)
3740

src/utils/transforms.cljs

-11
Original file line numberDiff line numberDiff line change
@@ -49,14 +49,3 @@
4949
(map? x) (reduce-kv convert-keys-and-values #js {} x)
5050
(vector? x) (to-array (mapv styles-with-vectors x))
5151
:else (clj->js x)))
52-
53-
(defn copy-js-obj-to-map
54-
"Copy `obj` keys and values into `m` if `(pred obj-key)` is satisfied."
55-
[obj m pred]
56-
(persistent!
57-
(reduce (fn [acc js-prop]
58-
(if (pred js-prop)
59-
(assoc! acc js-prop (oops/gobj-get obj js-prop))
60-
acc))
61-
(transient m)
62-
(js-keys obj))))

test/appium/views/base_view.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ def click(self, times_to_click=3):
4141
class UnreadMessagesCountText(Text):
4242
def __init__(self, driver, parent_locator: str):
4343
super().__init__(driver,
44-
xpath="%s/*[@resource-id='counter-component']/android.widget.TextView" % parent_locator)
44+
xpath="%s//*[@resource-id='counter-component']/android.widget.TextView" % parent_locator)
4545

4646

4747
class TabButton(Button):

0 commit comments

Comments
 (0)