在ClojureScript代理中使用React Native MapView [英] Using React Native MapView in ClojureScript Reagent
问题描述
我正在尝试使用:
(defn jsx-> clj[X](放入{}(用于[k(.keys js/Object x)] [k(age x k)]))))(定义我的地图[](让[this(r/current-component)][地图视图{:style {:flex 1}:initialRegion {:纬度37.78825:经度-122.4324:latitudeDelta 0.0922:longitudeDelta 0.0421}:onRegionChange(fn [region];;想在这里看到状态.(警告组件..."(str(jsx-> clj this)))}])))
打印的内容如下:
不确定该组件是否可以执行任何操作,我认为您需要 Region
信息.
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 onRegionChange
callback has Region
as argument. Region
has the following signature:
type Region {
latitude: Number,
longitude: Number,
latitudeDelta: Number,
longitudeDelta: Number,
}
You can get the values from the Region by using goog.object/get
.
If you get the region
and extract the values from it your my-map
looks like:
(defn my-map []
[map-view {:style {:flex 1}
:initialRegion {:latitude 52.3702
:longitude 4.89516
:latitudeDelta 0.0922
:longitudeDelta 0.0421}
:onRegionChange (fn [region]
(alert (str "Latitude: "
(goog.object/get region "latitude")
"\nLongitude: "
(goog.object/get region "longitude"))))}])
You can obtain the latitudeDelta
and longitudeDelta
in 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:
(defn jsx->clj
[x]
(into {} (for [k (.keys js/Object x)] [k (aget x k)])))
(defn my-map []
(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 [region]
;; Would like to see state here.
(alert "The component..."
(str (jsx->clj this))))}]))
This prints something like:
Not sure if you can do anything with the component, I think you need the Region
information.
这篇关于在ClojureScript代理中使用React Native MapView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!