I am trying to use MapView from https://github.com/airbnb/react-native-maps using Reagent. It works fine but how could I get local state for MapView when onRegionChange event is fired? Trying to use current/component but it is always nil.
(def Expo (js/require "expo"))
(def map-view (r/adapt-react-class (.-MapView Expo)))
(defn my-map []
(r/create-class
{:component-did-mount (fn [this]
(println "component mount "))
:reagent-render (fn []
(let [this (r/current-component)]
[map-view {:style {:flex 1}
:initialRegion {:latitude 37.78825
:longitude -122.4324
:latitudeDelta 0.0922
:longitudeDelta 0.0421}
:onRegionChange (fn []
;; Would like to see state here.
(println (.. this -state)) )}]))}))
Region information
The
onRegionChangecallback hasRegionas argument.Regionhas the following signature:You can get the values from the Region by using
goog.object/get.If you get the
regionand extract the values from it yourmy-maplooks like:You can obtain the
latitudeDeltaandlongitudeDeltain the same manner.When you drag the map the latitude and longitude show up:
The component
If you want access to the component itself your code works fine, you just have to visualize it:
This prints something like:
Not sure if you can do anything with the component, I think you need the
Regioninformation.