Fork me on GitHub
#cljsrn
<
2019-08-12
>
vinurs08:08:22

in react native, i access the global data global.HermesInternal like this (.-HermesInternal js/global), but the console shows that ReferenceError: global is not defined

thheller08:08:27

oh that might be a side effect of the loading changes I did

vikeri08:08:24

@titov the same way you would get it with JS React Native. Look at http://www.spacjer.com/blog/2014/09/12/clojurescript-javascript-interop/ it’s a bit outdated though in terms of accessing javascript objects. For that you can check: http://www.spacjer.com/blog/2014/09/12/clojurescript-javascript-interop/

Maksym09:08:29

I'm trying to import js module inside my app with this code:

(def Geolocation (js/require "react-native-geolocation-service"))
and it says there is no such module, although I have installed it with npm. It's so strange cause react and react-native I can import easily

vinurs08:08:31

i remember that some weeks ago i can access by this method

Maksym10:08:33

Yes and I can't import it, here is my code: (def Geolocation (js/require "react-native-geolocation-service"))

Maksym10:08:08

I installed js module with npm

lepistane11:08:20

if u read first sentence

lepistane11:08:29

As a browser polyfill, this API is available through the navigator.geolocation global - you do not need to import it.

lepistane11:08:46

and there is nothing to be installed

Maksym11:08:30

Yeah, you right, so how can I access methods of this module? I've tried

(.-requestAuthorization  (.-geolocation js/navigator))
for getting access but it's an object not a method 😕

Maksym11:08:31

android:futuree-app.android.core=>  (.-requestAuthorization  (.-geolocation js/navigator))
#object[requestAuthorization]
android:futuree-app.android.core=> (.-geolocation js/navigator)
#js {:setRNConfiguration #object[setRNConfiguration], :requestAuthorization #object[requestAuthorization], :getCurrentPosition #object[getCurrentPosition], :watchPosition #object[watchPosition], :clearWatch #object[clearWatch], :stopObserving #object[stopObserving]}

lepistane12:08:07

have a look into those interop articles shared by @U0AU4CPTN

Maksym12:08:19

Sorry I still don't understand. I try to call navigation.geolocation.requestAuthorization() but it's impossible, there is only object navigation.geolocation.requestAutorization: android:futuree-app.android.core=> (.requestAutorization (.-requestAuthorization (.-geolocation js/navigator))) #object[TypeError TypeError: navigator.geolocation.requestAuthorization.requestAutorization is not a function. (In 'navigator.geolocation.requestAuthorization.requestAutorization()', 'navigator.geolocation.requestAuthorization.requestAutorization' is undefined)]

eval code
eval@[native code]
figwheel$client$utils$eval_helper
nil
android:futuree-app.android.core=> (.requestAuthorization  (.-geolocation js/navigator))
#object[TypeError TypeError: RCTLocationObserver.requestAuthorization is not a function. (In 'RCTLocationObserver.requestAuthorization()', 'RCTLocationObserver.requestAuthorization' is undefined)]
requestAuthorization@http://localhost:8081/index.android.delta?platform=android&dev=true&minify=false:29973:47

lepistane15:08:52

u should really read articles people here are sending you. If something doesn't work it means u are doing something wrong. As i am getting strong vibes that u are beginner i will explain in detail how to call the fn. Read articles again and bookmark them use them as reference whenever you are using anything JS in CLJS. in order to get call that fn u need do the the following (.requestAuthorization js/navigator.geolocation) any global variable or object in JS world is accessed by using js namespace so here u are saying "give me navigator.geolocation object from js namespace and call requestAuthorization function

Maksym16:08:32

You are right, I'm beginner, I set a goal and I want to understand how this technology works, I really try to do my best, I read article and man, you write me code which does not work. I assume that there is no such function like requestAuthorization:

android:futuree-app.android.core=> (.requestAuthorization js/navigator.geolocation)
#object[TypeError TypeError: RCTLocationObserver.requestAuthorization is not a function]
java.net.MalformedURLException: unknown protocol: blob
        at java.base/java.net.URL.<init>(URL.java:657)
        at java.base/java.net.URL.<init>(URL.java:546)
        at cljs.repl$mapped_frame.invokeStatic(repl.cljc:332)
...
I checked it after connecting to react native debugger and working with navigator.geolocation object. Now I'm trying to just get current position with: (.getCurrentPosition js/navigator.geolocation #(fn [pos] (.alert (.-Alert ReactNative) pos)))

lepistane17:08:27

I like your ambition. good, this is good for getting the coordinates. Be sure to set optional settings as i had bug where cached values was taken after first position request. That should've worked 'cause the logic is the same when u call other functions (in ur case getCurrentPosition) If you inspect the object navigator.geolocation - it contains object getCurrentPosition The reason why requestAuthorization doesn't work could be many things 1. you didn't add permission 2. there is a problem with RN and your desired device I should've tested the code on my side before posting it. Apologies for that