Fork me on GitHub
#cljsrn
<
2016-12-21
>
raspasov06:12:05

@rukor yea I've dealt with this as well

raspasov06:12:30

(defn set-input-text! [component k s] (let [refs-m (js->clj (.-refs component) :keywordize-keys true) c (get refs-m k)] (when c (.setNativeProps c (clj->js {:text s}))))) (defn default-on-change-text ([new-text ks] (default-on-change-text new-text ks identity)) ([new-text ks value-f] (default-on-change-text new-text ks value-f nil)) ([new-text ks value-f ref-id] (fn [c] (let [new-value (value-f new-text)] ;set native props (when (keyword? ref-id) (set-input-text! c ref-id new-value)) (om/update-state! c (fn [old-state] (assoc-in old-state ks new-value)))))))

raspasov06:12:13

damn it slack how do I do this lol

raspasov06:12:46

but yea that's the code... using om-next but the only thing you'd have to change is om/update-state! to whatever your favorite library does to change local state

raspasov06:12:06

bottom line: (.setNativeProps ...) was the magic I found

pesterhazy10:12:20

@raspasov use triple backticks before and after string to code-quote

pesterhazy10:12:39

easier than markdown actually, it doesn't even have to be in a new line

pesterhazy10:12:21

@raspasov that snippet's for avoiding input lag, correct?

pesterhazy10:12:55

can you elaborate a bit how that works so I can port it to reagent?

levitanong15:12:33

@pesterhazy: I think he is forcing the props to change immediately while waiting for the whole app state to change

raspasov15:12:37

@pesterhazy looking at what I did here, I'm not sure it's the best idea, it's a little bit of a lie; I'm directly and mutably setting the native prep (via .SetNativeProps) AND saving the most recent input value into local state

raspasov15:12:06

the real reason for that is because I already had the code that was collecting/grabbing from local state

raspasov15:12:29

and I didn't want to re-write that when I discovered towards the end that there's no other way to make it lag-free

raspasov15:12:44

except for setting the native prop mutably

raspasov15:12:44

@levitanong yes and I'm actually NOT driving the value of the input field with local or any state at all

raspasov15:12:58

it's just directly being set on every tap/keystroke

raspasov15:12:13

I could not get it lag-free with anything else

levitanong15:12:20

It's definitely better than how I've been doing it.

raspasov15:12:33

so like here...

raspasov15:12:42

(text-input {:style        text-input-style
                               :autoCorrect  false
                               :editable     false
                               :maxLength    5
                               :ref          "input-billing-zip"
                               :onChangeText (fn [new-text] (put! comm-ch (u/default-on-change-text new-text [:form-data ::specs-next/zip])))
                               :keyboardType "number-pad"
                               :placeholder  "Billing Zip"})

levitanong15:12:29

Interesting. You're running a spec to validate the input?

raspasov15:12:47

works great for that!

raspasov15:12:58

but I run it on "Submit" press

levitanong15:12:41

Ah, I was wondering why there was no callback for when the spec complains

raspasov15:12:47

you could probably run it on every tap of you wanted to, *probably* won't be an issue but haven't tried it

levitanong15:12:53

As a side note: Have you been running into performance issues on om.next? I'm using it too, and it's starting to bog down. :(

raspasov15:12:13

generally, no

raspasov15:12:25

just fyi, my experience is iOS only

raspasov15:12:06

what generation phones are you targeting? and what specifically are you trying to achieve

levitanong15:12:22

Well, navigatorExperimental uses the JavaScript thread so I'm not that surprised

raspasov15:12:44

yea... I'm not using that... (nav xp)

levitanong15:12:03

Haha I'm also thinking of switching back to navigatorios

raspasov15:12:10

iPad Air? what phone is that similar to?

levitanong15:12:23

Hmmm lemme check

raspasov15:12:42

so I've tried everything down to iPhone 5

levitanong15:12:10

It uses the A8X chip. Recent generation. Definitely more powerful than the iPhone 5.

raspasov15:12:30

our apps runs very smooth on iPhone 6s, 7, reasonable on iPhone 6, and passable on iPhone 5

levitanong15:12:32

Have you been using navigatorios, or just navigator?

raspasov15:12:39

none of that

raspasov15:12:54

keeping it simple : )

raspasov15:12:00

+ a few libraries of course

raspasov15:12:03

like BlurView

levitanong15:12:08

Ah, well it's pretty performant using those

raspasov15:12:29

what specifically are you running into problems with?

levitanong15:12:50

Navigator animations dropping frames

raspasov15:12:58

hm yea... are you trying to

raspasov15:12:10

sliding back with a finger?

raspasov15:12:13

like Safari style?

raspasov15:12:23

just pressing tap?

levitanong15:12:34

The back is no problem

raspasov15:12:54

yea, I know very little about NavXp... tried it literally for a few hours

levitanong15:12:02

But I think the fact that a transact is happening plus a large part of the ui is updating is competing with the forward animation

raspasov15:12:15

and gave up switching lol (my goal was to try to make the sliding finger as back work with a very native feel)

raspasov15:12:24

but it's not critical for our app at all so I gave up

raspasov15:12:46

so one trick I've done

raspasov15:12:59

if your next/coming in screen has a ton of views

levitanong15:12:06

Placeholder?

raspasov15:12:07

it might lag, yes

raspasov15:12:31

so it depends on what your UI looks like

raspasov15:12:42

but you can do what I'd call

raspasov15:12:48

incremental hacky rendering

misha15:12:35

@levitanong have you tried wrapping app-logic parts of callbacks in those?

(def interaction-manager (.-InteractionManager ReactNative))
(defn run-after-interactions [f]
  (.runAfterInteractions interaction-manager f))
;or
(defn later [f]
  (fn []
    (request-animation-frame #(run-after-interactions f))))

levitanong15:12:38

@misha yup, I have! Fixes some problems, but not others

misha15:12:44

also, going forward to a blank page, and later refreshing it with changes (like slack does upon start up) - helps too

raspasov15:12:06

@levitanong so you have something like

(om/set-state! this {;local state performance optimizations
                     :perf-load-1                     false})

misha15:12:26

it is tall js tower on top of huge amount of RN code, after all harold

raspasov15:12:49

(animated-timing-start
        (animated-timing
          bottom-anim
          anim-m)
        (fn [_]
          ;allow loading of cards
          (u/log-transact! this `[(~'cards ~(hash-map :f (fn [_] :loading)))
                                  :cards])
          (om/update-state! this #(assoc % :perf-load-1 true))))

raspasov15:12:09

render the thing after the animation is done

raspasov15:12:19

similar to what @misha suggested I think

raspasov15:12:26

but you do it manually for parts of the UI

raspasov15:12:33

not pleasant but you gain the most control

levitanong15:12:45

It's kind of weird though. The big stuff changing isn't even being animated. It's on a different part of the UI

raspasov15:12:11

mine was kinda of a code organization/design problem from the start

levitanong15:12:15

I guess I'll have to try with a timeout first haha

levitanong15:12:29

Sounds like a design problem on my part too. Haha

raspasov15:12:31

so we have a checkout flow and it loads all the views all at once

misha15:12:32

+ this is the exact reason RN animation is done by mutating ui nodes' attributes directly, bypassing lifecycle methods train

raspasov15:12:49

so any time you have a big jump in the number of view on the screen

raspasov15:12:56

it might cause frames to drop

raspasov15:12:16

like with one tap the # of views on the screen jump by like 100!

raspasov15:12:24

since it renders a ton of forms and nested views

levitanong15:12:32

That's the tricky thing about iPad. :( so much space

raspasov15:12:56

didn't think of that - but good to keep in mind if I ever focus on iPad

raspasov15:12:04

use the perf monitor

raspasov15:12:16

to see how many views you're adding to the screen at once

raspasov15:12:21

it should show view count

misha15:12:23

if routing animations happen on the main thread - you share those 16ms you have to run your logic with animation logic

levitanong15:12:45

@raspasov Ahh, didn't know that's what it was for. Was only using it to look at FPS

raspasov15:12:47

and if you can keep it low or split it into chunks of showing up, it should help

raspasov15:12:00

there's a thing that counts, the views yes

misha15:12:07

perf monitor is pretty much useless on simulator harold

raspasov15:12:20

and also on dev builds!

levitanong15:12:24

@misha: haha I'm using a real device so I expect it to be really useful

raspasov15:12:39

btw @levitanong you're testing all of this with a prod build right?

raspasov15:12:44

perf on a dev build sucks big time

raspasov15:12:53

try production

raspasov15:12:57

you'd be amazed

raspasov15:12:08

like easily 2-4x difference in perf

raspasov15:12:23

I can bet on that : )

levitanong15:12:27

But will perf monitor exist on prod?

misha15:12:29

will keep you busy fixing "cannot build production because of reasons" errors for a while kappa

levitanong15:12:40

Ok thought so haha

levitanong15:12:47

Ok this is enough for me to go on.

raspasov15:12:49

that's the most annoying part of RN tbh

raspasov15:12:54

how long it takes to make a prod build

raspasov15:12:08

np ofc, any time

raspasov15:12:16

I use RN every day so chat any time!

raspasov15:12:25

we have a prod app with it

raspasov15:12:46

btw final thing: GREAT library

levitanong15:12:48

Will try not to abuse your hospitality

raspasov15:12:54

that I just found

raspasov15:12:10

@levitanong appreciate it, np : )

raspasov15:12:35

it can actually be so great to animate parts of the UI with placeholders!

raspasov15:12:54

very nice declarative animations, should have used it sooner

levitanong15:12:00

@raspasov: oh hey that's great!

levitanong15:12:07

Will play with it. Thanks for he heads up!

raspasov15:12:37

@misha I like their Animated API a lot too! it's actually just at the right level imo to make great custom animations

levitanong15:12:55

@misha yeah animated is pretty cool for custom animations

raspasov15:12:56

but the animatable library def is faster to get started for many cases

levitanong15:12:18

Anyway, gotta go guys! See ya! Thanks again!

misha15:12:13

not linking just API, but an actual book – great read for understanding what's up

levitanong16:12:35

has anyone updated to xcode 8.2.1?

levitanong21:12:42

also, has anyone gotten om.next to work with boot-react-native?

raspasov23:12:17

@levitanong Xcode 8.2 right now, I use re-natal, it has worked well