Fork me on GitHub
#cljsrn
<
2017-04-26
>
harrybin06:04:37

@mengu, not android drawer, but have used DrawerNavigator from http://reactnavigation.org

kurt-o-sys13:04:25

I'm trying to get react-native-signalone to work with cljsrn. It shouldn't be that hard:

import OneSignal from 'react-native-onesignal'

export default class App extends Component {
    componentWillMount() {
        OneSignal.addEventListener('received', this.onReceived);
        ...
     }
     onReceived(notification) {
          ...
     }
Translating to cljsrn (rum/re-natel):
(def OneSignal (js/require "react-native-onesignal"))
(defn ^:export onreceived [notification]
    ...)
(def one-signal-mixin
  {:will-mount   (fn [state]
                   (doto OneSignal
                     (.addEventListener "received" onreceived))
    ...
  })
(defc AppRoot < rum/reactive one-signal-mixin
  [state]
  ...
)

kurt-o-sys13:04:34

However, I'm getting this error:

kurt-o-sys13:04:06

can't find what I'm doing wrong...

kurt-o-sys13:04:28

$ cat index.android.js 
var modules={'react-native': require('react-native'), 'react': require('react')}; ... ;modules['react-native-onesignal']=require('react-native-onesignal');
require('figwheel-bridge').withModules(modules).start('...');

misha13:04:42

probably you did not get OneSignal imported

kurt-o-sys13:04:20

ok, makes sense... so... why, or how to make it imported? I thought this line (def OneSignal (js/require "react-native-onesignal")) would do?

dehli13:04:56

You should try console logging it (and removing the rest of your OneSignal logic)

dehli13:04:12

that way you can verify that it’s the issue

misha13:04:54

try something like (def OneSignal (.-default (js/require "react-native-onesignal")))

misha13:04:45

or just enable chrome dev tools debugging and (js/console.log OneSignal) right after import

kurt-o-sys13:04:47

(def OneSignal (.-default (js/require "react-native-onesignal"))) does seem to help - no error so far. What's the reason?

misha13:04:57

you did not import correctly first time? kappa

kurt-o-sys13:04:58

well... that .-default did the trick. Oh, export default class OneSignal - I'm not very familiar with ES6 (it is ES6, right? :p)

kurt-o-sys13:04:42

so, OneSignal is available as export (at least in cljs... in js, one seem to be able to use OneSignal - oh, I think I get it: static methods?)

misha13:04:02

if something is exported as default - you need to explicitly "navigate" to it. basically require gives you "js ns object". An actual class you need will either be in ns.default or in ns.ActualClass (and maybe it will be ns in case of es5?). so you have 3 things to try:

(def MyClass (js/require "some-lib"))
 ;; or
(def MyClass (.-default (js/require "some-lib")))
 ;; or
(def MyClass (.-MyClass (js/require "some-lib")))

manu14:04:11

Hi all! where I can find some examples about react native navigator with clojurescript? thanks!

vikeri14:04:59

@manu You probably don’t want to use that, it’s very object oriented and I don’t think it’s very maintained

savelichalex14:04:26

and have performance problems)

manu15:04:33

unfortunately I have no choise (now)😥

manu15:04:17

I'm studying a code made by another and in the future I'll improve it. but for now I'm just trying to understand the code ^^'

manu15:04:40

and because of there is navigator, but it is used in a very hard way, I would like to see some easier examples 🙂

benny15:04:57

The examples above mentioned by @amorokh are pretty straight forward, there are lots of reasons to not use navigator (not even specific to clj)

manu16:04:09

I'll see them and I'll try to figure it out 🙂

manu16:04:16

thaks 🙂