Skip to content

Commit

Permalink
更新项目
Browse files Browse the repository at this point in the history
  • Loading branch information
qiuxiang committed Feb 17, 2022
1 parent bf8e086 commit 0914150
Show file tree
Hide file tree
Showing 12 changed files with 105 additions and 59 deletions.
25 changes: 15 additions & 10 deletions android/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ import com.android.build.OutputFile
*/

project.ext.react = [
enableHermes: false, // clean and rebuild if changing
enableHermes: true, // clean and rebuild if changing
]

apply from: "../../node_modules/react-native/react.gradle"
Expand All @@ -91,7 +91,7 @@ apply from: "../../node_modules/react-native/react.gradle"
* Upload all the APKs to the Play Store and people will download
* the correct one based on the CPU architecture of their device.
*/
def enableSeparateBuildPerCPUArchitecture = false
def enableSeparateBuildPerCPUArchitecture = true

/**
* Run Proguard to shrink the Java bytecode in release builds.
Expand All @@ -114,22 +114,22 @@ def jscFlavor = 'org.webkit:android-jsc:+'
/**
* Whether to enable the Hermes VM.
*
* This should be set on project.ext.react and mirrored here. If it is not set
* This should be set on project.ext.react and that value will be read here. If it is not set
* on project.ext.react, JavaScript will not be compiled to Hermes Bytecode
* and the benefits of using Hermes will therefore be sharply reduced.
*/
def enableHermes = project.ext.react.get("enableHermes", false);

/**
* Architectures to build native code for in debug.
*/
def nativeArchitectures = project.getProperties().get("reactNativeDebugArchitectures")

android {
ndkVersion rootProject.ext.ndkVersion

compileSdkVersion rootProject.ext.compileSdkVersion

compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}

defaultConfig {
applicationId "com.rnamapgeolocation"
minSdkVersion rootProject.ext.minSdkVersion
Expand All @@ -156,6 +156,11 @@ android {
buildTypes {
debug {
signingConfig signingConfigs.debug
if (nativeArchitectures) {
ndk {
abiFilters nativeArchitectures.split(',')
}
}
}
release {
// Caution! In production, you need to generate your own keystore file.
Expand Down Expand Up @@ -191,7 +196,7 @@ dependencies {
implementation "androidx.swiperefreshlayout:swiperefreshlayout:1.0.0"

debugImplementation("com.facebook.flipper:flipper:${FLIPPER_VERSION}") {
exclude group:'com.facebook.fbjni'
exclude group:'com.facebook.fbjni'
}

debugImplementation("com.facebook.flipper:flipper-network-plugin:${FLIPPER_VERSION}") {
Expand All @@ -215,7 +220,7 @@ dependencies {
// Run this once to be able to run the application with BUCK
// puts all compile dependencies into folder libs for BUCK to use
task copyDownloadableDepsToLibs(type: Copy) {
from configurations.compile
from configurations.implementation
into 'libs'
}

Expand Down
36 changes: 36 additions & 0 deletions android/app/src/main/res/drawable/rn_edit_text_material.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright (C) 2014 The Android Open Source Project
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<inset xmlns:android="http://schemas.android.com/apk/res/android"
android:insetLeft="@dimen/abc_edit_text_inset_horizontal_material"
android:insetRight="@dimen/abc_edit_text_inset_horizontal_material"
android:insetTop="@dimen/abc_edit_text_inset_top_material"
android:insetBottom="@dimen/abc_edit_text_inset_bottom_material">

<selector>
<!--
This file is a copy of abc_edit_text_material (https://bit.ly/3k8fX7I).
The item below with state_pressed="false" and state_focused="false" causes a NullPointerException.
NullPointerException:tempt to invoke virtual method 'android.graphics.drawable.Drawable android.graphics.drawable.Drawable$ConstantState.newDrawable(android.content.res.Resources)'
<item android:state_pressed="false" android:state_focused="false" android:drawable="@drawable/abc_textfield_default_mtrl_alpha"/>
For more info, see https://bit.ly/3CdLStv (react-native/pull/29452) and https://bit.ly/3nxOMoR.
-->
<item android:state_enabled="false" android:drawable="@drawable/abc_textfield_default_mtrl_alpha"/>
<item android:drawable="@drawable/abc_textfield_activated_mtrl_alpha"/>
</selector>

</inset>
2 changes: 1 addition & 1 deletion android/app/src/main/res/values/styles.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.DayNight.NoActionBar">
<!-- Customize your theme here. -->
<item name="android:textColor">#000000</item>
<item name="android:editTextBackground">@drawable/rn_edit_text_material</item>
</style>

</resources>
22 changes: 13 additions & 9 deletions android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,25 @@

buildscript {
ext {
buildToolsVersion = "29.0.3"
buildToolsVersion = "30.0.2"
minSdkVersion = 21
compileSdkVersion = 29
targetSdkVersion = 29
ndkVersion = "20.1.5948944"
compileSdkVersion = 30
targetSdkVersion = 30
ndkVersion = "21.1.6352462"
}
repositories {
google()
jcenter()
mavenCentral()
}
dependencies {
classpath("com.android.tools.build:gradle:4.1.0")
classpath("com.android.tools.build:gradle:4.2.2")
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}

allprojects {
repositories {
mavenLocal()
maven {
// All of React Native (JS, Obj-C sources, Android binaries) is installed from npm
url("$rootDir/../node_modules/react-native/android")
Expand All @@ -30,9 +29,14 @@ allprojects {
// Android JSC is installed from npm
url("$rootDir/../node_modules/jsc-android/dist")
}

mavenCentral {
// We don't want to fetch react-native from Maven Central as there are
// older versions over there.
content {
excludeGroup "com.facebook.react"
}
}
google()
jcenter()
maven { url 'https://www.jitpack.io' }
}
}
4 changes: 2 additions & 2 deletions android/gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

# Specifies the JVM arguments used for the daemon process.
# The setting is particularly useful for tweaking memory settings.
# Default value: -Xmx10248m -XX:MaxPermSize=256m
# Default value: -Xmx1024m -XX:MaxPermSize=256m
# org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8

# When configured, Gradle will run in incubating parallel mode.
Expand All @@ -25,4 +25,4 @@ android.useAndroidX=true
android.enableJetifier=true

# Version of flipper SDK to use with React Native
FLIPPER_VERSION=0.75.1
FLIPPER_VERSION=0.99.0
2 changes: 1 addition & 1 deletion android/gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-6.7-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-7.2-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
22 changes: 10 additions & 12 deletions index.js → index.tsx
Original file line number Diff line number Diff line change
@@ -1,20 +1,22 @@
import React from "react";
import * as React from "react";
import {
AppRegistry,
Button,
PermissionsAndroid,
Platform,
ScrollView,
StyleSheet,
Text,
View,
ScrollView,
PermissionsAndroid,
Platform,
} from "react-native";
import {
init,
Geolocation,
init,
Position,
PositionError,
setInterval,
setNeedAddress,
setLocatingWithReGeocode,
setNeedAddress,
} from "react-native-amap-geolocation";

const style = StyleSheet.create({
Expand All @@ -40,6 +42,7 @@ const style = StyleSheet.create({

class App extends React.Component {
state = { location: null };
watchId?: number | null;

async componentDidMount() {
if (Platform.OS === "android") {
Expand All @@ -55,13 +58,8 @@ class App extends React.Component {
});
}

componentWillUnmount() {
stop();
}

updateLocationState(location) {
updateLocationState(location: Position | PositionError) {
if (location) {
location.updateTime = new Date().toLocaleString();
this.setState({ location });
console.log(location);
}
Expand Down
2 changes: 1 addition & 1 deletion license
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2020 7c00 <i@7c00.cc>
Copyright (c) 2022 7c00 <i@7c00.cc>

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
9 changes: 4 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,8 @@
"lib/android/src",
"lib/android/build.gradle"
],
"main": "lib/js",
"main": "src",
"scripts": {
"dev": "tsc -w",
"build": "tsc",
"build-docs": "npx typedoc --out docs/api --excludeNotExported --module commonjs --mode file src",
"start": "react-native start",
"reload": "adb reverse tcp:8081 tcp:8081 && adb shell input text rr",
Expand All @@ -33,8 +31,9 @@
"ios": "react-native run-ios"
},
"devDependencies": {
"react": "17.0.1",
"react-native": "0.64.0"
"@types/react-native": "^0.66.16",
"react": "17.0.2",
"react-native": "0.67.2"
},
"prettier": {
"printWidth": 100
Expand Down
4 changes: 2 additions & 2 deletions readme.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# react-native-amap-geolocation [![npm version][version-badge]][npm] [![build status][build-badge]][build]
# react-native-amap-geolocation [![][version-badge]][npm] [![][build-badge]][build]

React Native 高德地图定位模块,支持 Android + iOS,提供尽可能完善的原生接口,
同时提供符合 Web 标准的 Geolocation API。
Expand All @@ -18,7 +18,7 @@ await PermissionsAndroid.requestMultiple([

await init({
ios: "9bd6c82e77583020a73ef1af59d0c759",
android: "043b24fe18785f33c491705ffe5b6935"
android: "043b24fe18785f33c491705ffe5b6935",
});

Geolocation.getCurrentPosition(({ coords }) => {
Expand Down
24 changes: 12 additions & 12 deletions src/geolocation.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { EmitterSubscription } from "react-native";
import { start, stop, addLocationListener, _options } from "./amap-geolocation";
import { addLocationListener, start, stop, _options } from "./amap-geolocation";
import { Location } from "./types";

/**
Expand Down Expand Up @@ -81,12 +81,12 @@ export default class Geolocation {
*/
static getCurrentPosition(
success: (position: Position) => void,
error?: (error: PositionError) => void,
options: PositionOptions = {}
error?: (error: PositionError) => void
// options: PositionOptions = {}
) {
const listener = addLocationListener((location) => {
if (location.errorCode) {
error && error(new PositionError(location.errorCode, location.errorInfo, location));
error && error(new PositionError(location.errorCode, location.errorInfo ?? "", location));
stop();
return listener.remove();
}
Expand All @@ -107,12 +107,12 @@ export default class Geolocation {
*/
static watchPosition(
success: (position: Position) => void,
error?: (error: PositionError) => void,
options?: PositionOptions
error?: (error: PositionError) => void
// options?: PositionOptions
) {
watchMap[++watchId] = addLocationListener((location) => {
if (location.errorCode) {
error && error(new PositionError(location.errorCode, location.errorInfo, location));
error && error(new PositionError(location.errorCode, location.errorInfo ?? "", location));
} else {
success(toPosition(location));
}
Expand Down Expand Up @@ -140,12 +140,12 @@ function toPosition(location: Location) {
coords: {
latitude: location.latitude,
longitude: location.longitude,
altitude: location.altitude,
altitude: location.altitude ?? 0,
accuracy: location.accuracy,
altitudeAccuracy: null, // 高德定位接口没有找到对应的数据
heading: location.heading,
speed: location.speed,
altitudeAccuracy: 0, // 高德定位接口没有找到对应的数据
heading: location.heading ?? 0,
speed: location.speed ?? 0,
},
timestamp: location.timestamp,
timestamp: location.timestamp ?? 0,
};
}
12 changes: 8 additions & 4 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
{
"compilerOptions": {
"declaration": true,
"lib": ["es2015"],
"outDir": "lib/js"
"strict": true,
"lib": ["esnext"],
"jsx": "react-native",
"baseUrl": ".",
"paths": {
"react-native-amap-geolocation": ["src"]
}
},
"files": ["src/index.ts"]
"files": ["index.tsx"]
}

0 comments on commit 0914150

Please sign in to comment.