Hacker News new | ask | show | jobs
by cel1ne 3659 days ago
I'm working on an Android app.

I use react-native solely for the UI which I update, redux-style, with a state-tree. The state and all it's transition and event-handling is done in Kotlin/Java. I've written a small helper that generates kotlin-Interfaces from the react/jsx-files and automatically connects everything.

This way I have react's HotReload and the other benefits for UI-design and a proper typed language and IDE for networking and everything else. Including compile-time checking of events and properties of the UI.

Plus: Kotlin can compile to JavaScript, so if I ever want to port the whole thing to iOS, i just have to switch out a few APIs.

2 comments

Just to mention, if you enjoy Kotlin - you might want to try Anvil+Bansa. It is like React+Redux, but for Kotlin (or Java). Resulting APKs are much smaller than React Native and don't rely on jni code.

http://anvil.site/

https://github.com/brianegan/bansa

I've thought about Anvil, but I like React and I can reuse stuff from my web-development. Like tachyons styling [0].

Regarding bansa: Sounds nice, but I've never seen the benefit of using a library for state and state-reduction. You can implement and customise for yourself in less than 50 lines. (I don't use the redux library on the web either)

The only thing I would like is being able to reuse data-structures of react-native, so they won't get serialized all the time.

Thanks for the tips, though!

[0] https://github.com/fab1an/react-native-tachyons

I want to add anko, which might be more idiomatic for kotlin.

https://github.com/Kotlin/anko

Wow that stuff looks pretty cool. Thanks for sharing!
Sounds like a great use case of React Native where RN is specifically used for what it is designed for: the UI layer. I've done apps with both approaches (all RN or UI-only RN), and I'd love to read or see more about your approach.
Maybe I'll write something longer about it, but i haven't figured everything out myself yet.

I have a Controller that takes UIEvents and NetworkEvents from a BlockingQueue (CSP). The state reduces everything. Kotlin's "when" constructs are extremely convenient here, but want to make sure I'm not going to far into the functional direction, if you get what I mean.

The state is completely serialisable (in fact gets serialised to and from JSON in onPause/onResume).

I'm doing networking declaratively as well, a serialisable request-description is put into the state and it's the "NetworkManager"'s job to figure out which requests to start or stop.

Kotlin's delegated property are also awesome, because I can mix and match functions and variables.

     /* show loading animation */
     override val isLoading by stateFn {
        it.runningRequests.any { it is LoginReq }
     }