Fork me on GitHub
#reagent
<
2021-03-15
>
zendevil.eth10:03:58

I’m trying to convert the following react native to reagent code:

const MyText = ({ weight, style, ...props }) => {
  return <Text style={[{ fontFamily : "Montserrat-Regular" }, style]}
  {...props} />
}

zendevil.eth10:03:16

This is what I have so far:

(defn text [{:keys [style weight] :as props}]
  [:> Text (merge (dissoc props :style) {:style [style {:fontFamily "Montserrat-Regular"}]})])

zendevil.eth10:03:54

But the problem is that the fontFamily style isn’t being applied to the component

juhoteperi11:03:04

@ps Is this on ReactNative? I think it supports arrays in style attribute, but React-DOM doesn't support them.

zendevil.eth11:03:18

yes it’s react native

juhoteperi11:03:01

Not sure why it doesn't work.

(defn text [{:keys [style weight] :as props}]
  [:> Text (assoc props :style (assoc style :fontFamily "Montserrat-Regular"))])
Would be the simplest and avoids the need to use array to merge styles.

zendevil.eth11:03:48

@juhoteperi I tried your snippet, but the fontFamily isn’t being applied to the component

juhoteperi11:03:06

Markup seems fine. I don't remember if devtools allows you to validate resulting RN element tree and properties. Might something else, like is the font available?

zendevil.eth11:03:24

@juhoteperi when I use the fontFamily directly in the style map, the font does show

zendevil.eth11:03:17

This is working:

[:> Text {:style {:fontFamily "Montserrat-Regular"
                  :marginLeft "12%" :fontWeight :bold :fontSize 25 :color :gray}}
    "Text"]

zendevil.eth11:03:02

when I use the custom component, it’s not like the text shows with the default font. The text doesn’t show at all

juhoteperi11:03:18

you custom component doesn't take or use children elements currently

juhoteperi11:03:58

If you want to use it like [text "foobar"] you need something like (defn text [props & children] (into [:> Text {...}] children))

zendevil.eth11:03:15

@juhoteperi thanks. It works now. But is this the most elegant way to do this?

juhoteperi11:03:26

Yes, I'd say so. React example didn't deal with the children directly because in React children are part of the props object (if you call createElement with additional children, they are just stored to props object children property). Reagent handles them differently to provide more "Clojurey" way to declare components using functions.

pinkfrog14:03:39

Hi . How to know which reagent works with react-native: “react-native”: “0.63.4" ?

p-himik14:03:27

Reagent works with particular versions of React. React Native works with particular versions of React. You just have to correspond the two by e.g. checking package.json of the relevant version of RN.

juhoteperi16:03:14

Reagent should also be quite backwards compatible with React versions, even if current default is 17, it should work fine with 16.

pinkfrog16:03:07

Does shadowcljs ignore

Dependencies
cljsjs/react 17.0.1-0
cljsjs/react-dom 17.0.1-0
cljsjs/react-dom-server 17.0.1-0
as in https://clojars.org/reagent ?

p-himik16:03:57

It does. You have to install the right NPM packages.

dima14:03:17

Hello. Re-posting here reagent ratom related question from #re-frame channel https://clojurians.slack.com/archives/C073DKH9P/p1615817216216500

dima12:03:46

General question: what happens to those undisposed subscriptions? Should they be always disposed when watching subscription gets disposed?

juhoteperi16:03:14

Reagent should also be quite backwards compatible with React versions, even if current default is 17, it should work fine with 16.

zendevil.eth16:03:35

Hi, I’m trying to use this library: https://github.com/FaridSafi/react-native-google-places-autocomplete#readme It contains the following example to use a custom Input Component:

import React from 'react';
import { Text, View, Image } from 'react-native';
import { GooglePlacesAutocomplete } from 'react-native-google-places-autocomplete';
import { Input } from 'react-native-elements';

const GOOGLE_PLACES_API_KEY = 'YOUR_GOOGLE_API_KEY';

const GooglePlacesInput = () => {
  return (
    <GooglePlacesAutocomplete
      query={{
        key: GOOGLE_PLACES_API_KEY,
        language: 'en', // language of the results
      }}
      onPress={(data, details) => console.log(data, details)}
      textInputProps={{
        InputComp: Input,
        leftIcon: { type: 'font-awesome', name: 'chevron-left' },
        errorStyle: { color: 'red' },
      }}
    />
  );
};

export default GooglePlacesInput;

zendevil.eth16:03:37

For which I have the following:

[:> GooglePlacesAutocomplete
     {:placeholder "Search For Event Address"
      :onPress (fn [data details]
                 (dispatch [:set-address data navigation])
                 (js/console.log "data" data "details" details))
      ;;:currentLocation true
      ;;:currentLocationLabel "Current Location"
      :query {:key "mykey"
              :language :en}
      :textInputProps {:InputComp 
                       (as-element
                        (fn [] [text-input {:style {:backgroundColor "#AC1815"
                                                    :borderRadius 10
                                                    :width "70%"
                                                    :fontFamily "Montserrat-Regular"
                                                    :height 50
                                                    :color :white
                                                    :fontWeight :bold
                                                    :paddingLeft 8
                                                    :paddingRight 8}}]))

                       }
      }]
So basically I’m using
(fn [] [text-input {:style {:backgroundColor "#AC1815"
                                                    :borderRadius 10
                                                    :width "70%"
                                                    :fontFamily "Montserrat-Regular"
                                                    :height 50
                                                    :color :white
                                                    :fontWeight :bold
                                                    :paddingLeft 8
                                                    :paddingRight 8}}])
as the textComp. However, this is giving me the following error:

zendevil.eth16:03:06

How to use a custom text component in this library?

p-himik16:03:09

Your usage of as-element is incorrect. Use it within the function and wrap the [text-input ...] hiccup vector with it.

zendevil.eth16:03:50

@p-himik this seems to give the correct result, but I also get a new warning now:

dima12:03:46

General question: what happens to those undisposed subscriptions? Should they be always disposed when watching subscription gets disposed?