cljsrn

https://github.com/drapanjanas/re-natal | https://github.com/drapanjanas/re-natal/wiki/FAQ | https://github.com/condense/mercury-app/wiki | https://github.com/seantempesta/expo-cljs-template/ https://www.npmjs.com/package/create-expo-cljs-app
zendevil 2021-01-17T10:36:51.002600Z

I’m having trouble using flatlist with react native

zendevil 2021-01-17T10:36:56.002800Z

I have the following code:

zendevil 2021-01-17T10:37:23.003400Z

[:> FlatList {:data @(subscribe [:videos])
                  :renderItem video-comp
                  :keyExtractor (fn [item] (:uri item))}]
and video-comp is given by:

zendevil 2021-01-17T10:37:32.003700Z

(defn video-comp [video]
  [:> View
   [:> Video
    {:style {:height 400
             :width "100%"}
     :controls true
     :paused true
     :source {:uri (:uri video)}}]
   [:> Text (:name video)]])

zendevil 2021-01-17T10:37:39.004Z

however, I’m getting the following error:

zendevil 2021-01-17T10:37:57.004300Z

Objects are not valid as a react child.

zendevil 2021-01-17T10:38:00.004500Z

How to fix this error?

pez 2021-01-17T10:42:17.006200Z

Not thought this through, so a long shot. You might need to make the video-comp a react-component. Something like:

:renderItem (r/create-component video-comp)

zendevil 2021-01-17T10:54:49.006600Z

I’ve tried both r/create-component and r/as-element, and am getting the same error

zendevil 2021-01-17T10:55:38.007Z

actually r/create-component gives a different error:

zendevil 2021-01-17T10:55:48.007300Z

undefined is not an object

zendevil 2021-01-17T10:56:06.007700Z

evaluating reagent.core.create-component.cljs…

zendevil 2021-01-17T12:35:40.008Z

I have another error

zendevil 2021-01-17T12:36:15.008700Z

(defn sample-comp []
[:> View [:> Text "Sample Container!"]])

(defn root-comp []
  [:> NavigationContainer
   [:> SafeAreaView
    (let [Tab (createBottomTabNavigator)]
      [:> (.-Navigator Tab)
       [:> (.-Screen Tab)
        {:name "Home"
         :component (r/reactify-component sample-comp)}]])]])

(defn init []
  ;; register error also occurs if there's a non-
  ;; related error in the code
  (dispatch [:register-db])
  (render-root "Humboi" (r/as-element [root-comp])))
Here’s my code in which I’m trying to use multiple bottom tabs using react navigation

zendevil 2021-01-17T12:36:22.008900Z

but I’m getting the following error:

zendevil 2021-01-17T12:36:52.009500Z

requireNativeComponent: “RNCSafeAreaProvider” was not found in UIManager.

zendevil 2021-01-17T12:36:56.009800Z

How to fix this error?

pez 2021-01-17T13:42:09.012200Z

With react navigation I have sometimes had to also call clj->js. And I’ve been using as-component I now realize. Here’s a snippet from my work-for-food project:

:navigationOptions 
(fn [_]
  (clj->js {:headerLeft  (r/as-component 
                          [nav-back-button {:on-press #(dispatch [:foo.leave])}])
            :headerTitle (r/as-component
                          (some-reagent-component))
            :headerRight (when env/android? (empty-component))}))

zendevil 2021-01-17T14:20:04.013Z

using as-component gives undefined is not an object

zendevil 2021-01-17T14:20:24.013500Z

is your r/ namespace reagent.core?

pez 2021-01-17T14:26:30.014100Z

Yes, reagent.core.

zendevil 2021-01-17T14:27:26.014400Z

as-component is giving undefined is not an object

pez 2021-01-17T14:30:14.015900Z

Which is strange. What do you get if you evaluate sample-component in the REPL?

zendevil 2021-01-17T14:35:09.017200Z

I’m getting Use of undeclared Var reagent.core/as-component

zendevil 2021-01-17T14:35:11.017400Z

in the repl

pez 2021-01-17T15:20:25.021600Z

I think I might be using an older version of reagent. Maybe this API has changed since…

zendevil 2021-01-17T18:17:29.022800Z

@admin055 that gives the error:

zendevil 2021-01-17T18:19:54.024600Z

I have the following:

zendevil 2021-01-17T18:19:57.024800Z

[:> FlatList {:data @(subscribe [:videos]) :renderItem (fn [] (r/as-element [video-comp])) :keyExtractor (fn [item] (:uri item))}]

zendevil 2021-01-17T18:20:02.025Z

and this crashes the app

zendevil 2021-01-17T18:21:35.025200Z

I also tried the following;

zendevil 2021-01-17T18:21:51.025500Z

[:> FlatList {:data @(subscribe [:videos])
                      :renderItem (fn [item] (r/as-element [video-comp item]))
                      :keyExtractor (fn [item] (:uri item))}]
       

zendevil 2021-01-17T18:21:54.025700Z

But this crashes the app

zendevil 2021-01-17T18:22:03.026Z

as well

joshmiller 2021-01-17T20:33:10.028300Z

@ps I have [:> FlatList {:render-item (fn [todo] (r/as-element [render-todo todo navigate true])) ; ...]

🙏 1
✅ 1
joshmiller 2021-01-17T20:33:48.028800Z

So r/as-element should work

joshmiller 2021-01-17T20:34:20.029500Z

I’d try the suggestion above about debugging the component below

zendevil 2021-01-17T20:39:57.029600Z

as-element with {:> View [:> Text “ok”]] works

zendevil 2021-01-17T20:43:41.029800Z

but using (:name item) in Text doesn’t work

2021-01-17T21:59:29.030Z

And like that, it should work.

[:> FlatList {:data @(subscribe [:videos])
                      :renderItem (fn [item] (r/as-element [:> View [:> Text (goog.object/get item "name")]]))
                      :keyExtractor (fn [item] (:uri item))}]

Oliver George 2021-01-17T22:11:51.030600Z

@ps here's a working example from my cljsrn app: https://gist.github.com/olivergeorge/97a5c7179d2e7076da68e9cc4dc0bea8

🙏 1
✅ 1
Oliver George 2021-01-17T22:11:53.030700Z

✅ 1
Oliver George 2021-01-17T22:13:21.031400Z

@ps regarding app crashes. I suspect you need a top level error boundary. Here's my code for that: https://gist.github.com/olivergeorge/ac9dbda3934de9d215083708501bf42c

👍 1
🙏 1
✅ 1
Oliver George 2021-01-17T22:13:24.031500Z

👏 1
🙏 1
✅ 1