cljsrn

Mikko Harju 2022-02-16T09:34:03.746219Z

What approaches there are to find out why https://callstack.github.io/react-native-paper/text-input.html this is "flickering" when I do the basic adapt-react-class to it and use re-frame subscription as the value and dispatch the value on-change-text? I've been able to get it to work properly if I use a functional component (reagent 1.1.0 feature) and use local hook state instead of re-frame. So – basically it seems to mount a new component every time instead of reusing the current when the value changes?e

joshmiller 2022-02-22T00:14:39.357239Z

@mikko Re the pointers to default-value above, see a full explanation here: https://increasinglyfunctional.com/2019/03/28/why-clojurescript-react-native-text-input-slow.html

Mikko Harju 2022-02-22T05:05:48.787159Z

Thanks all 🙂 I opted for the dispatch-sync & flush option since the component I'm using does not seem to have a default-value property (at least according to the docs) – and maybe I can provide my own textfield to the game but for now I'll stick to the first option

Mikko Harju 2022-02-16T09:46:02.857179Z

So just doing

[:> TextInput 
   {:label (t/translate :company-mobile.login/username)
    :value @username
    :onChangeText (fn [t] (re/dispatch [::login/set-username t]))}]
causes the flicker

lepistane 2022-02-16T09:48:52.046289Z

yeah basically. I know i had a solution for that let me check

lepistane 2022-02-16T10:03:06.884399Z

try to remove the :value if i am not mistaken it should prevent constant re-rendering

Mikko Harju 2022-02-16T10:05:56.585589Z

Yeah, that might work but if we want to get the initial value through the subscription that does not work. It has the render prop that can be used to give it a textfield to use – I'll try to use that.

Mikko Harju 2022-02-16T10:06:22.426309Z

I think the issue is the same as with web side when using material-ui we need to provide our own input field to it in order for it not to flicker

Mikko Harju 2022-02-16T10:15:13.990629Z

OK. I think I solved it 🙂 I just use

(fn [t]
  (re/dispatch-sync (conj dispatch t))
  (r/flush))
And the flickering stops

lepistane 2022-02-16T11:32:26.717929Z

removing :value didn't help? great 👍 thanks for sharing solution

Mikko Harju 2022-02-16T11:42:09.308599Z

@lepistane sure, removing :value works but if we want the field to be managed and use the value from the state it can't be removed. If eg. we have an initial value we want there then it's a hassle to get in

Mikko Harju 2022-02-16T11:42:21.712549Z

Thanks for your help as well!

👍 1
2022-02-16T13:50:38.835339Z

Try with :default-value

hadils 2022-02-18T19:49:00.123629Z

Use defaultValue