Fix tab not selecting and Error: No protocol method IDeref.-deref defined for type string: (#14194)

* Fix laziness and let defined in render
This commit is contained in:
Ibrahem Khalil 2022-10-20 14:04:13 +02:00 committed by GitHub
parent 258f92c691
commit 1aaa9acc80
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 15 additions and 14 deletions

View File

@ -10,21 +10,22 @@
(def default-tab-size 32) (def default-tab-size 32)
(defn tabs [{:keys [default-active on-change style]}] (defn tabs [{:keys [default-active on-change style]}]
(fn [{:keys [data size] :or {size default-tab-size}}] (let [active-tab-id (reagent/atom default-active)]
(let [active-id @default-active] (fn [{:keys [data size] :or {size default-tab-size}}]
[rn/view (merge {:flex-direction :row} style) [rn/view (merge {:flex-direction :row} style)
(for [{:keys [label id]} data] (doall
^{:key id} (for [{:keys [label id]} data]
[rn/view {:style {:margin-right (if (= size default-tab-size) 12 8)}} ^{:key id}
[tab/tab [rn/view {:style {:margin-right (if (= size default-tab-size) 12 8)}}
{:id id [tab/tab
:size size {:id id
:active (= id active-id) :size size
:on-press (fn [^js press-event id] :active (= id @active-tab-id)
(reset! default-active id) :on-press (fn []
(when on-change (reset! active-tab-id id)
(on-change press-event id)))} (when on-change
label]])]))) (on-change id)))}
label]]))])))
(defn- calculate-fade-end-percentage (defn- calculate-fade-end-percentage
[{:keys [offset-x content-width layout-width max-fade-percentage]}] [{:keys [offset-x content-width layout-width max-fade-percentage]}]