Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
70 changes: 69 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,69 @@
.DS_Store
.DS_Store
### Android template
# Built application files
*.apk
*.ap_

# Files for the ART/Dalvik VM
*.dex

# Java class files
*.class

# Generated files
bin/
gen/
out/

# Gradle files
.gradle/
build/

# Local configuration file (sdk path, etc)
local.properties

# Proguard folder generated by Eclipse
proguard/

# Log Files
*.log

# Android Studio Navigation editor temp files
.navigation/

# Android Studio captures folder
captures/

# IntelliJ
*.iml
.idea/workspace.xml
.idea/tasks.xml
.idea/gradle.xml
.idea/dictionaries
.idea/libraries

# Keystore files
# Uncomment the following line if you do not want to check your keystore files in.
#*.jks

# External native build folder generated in Android Studio 2.2 and later
.externalNativeBuild

# Google Services (e.g. APIs or Firebase)
google-services.json

# Freeline
freeline.py
freeline/
freeline_project_description.json

/build.gradle
gradle.properties
gradlew
gradlew.bat
react-native-phone-picker.iml
settings.gradle
gradle
.idea
.gradle

86 changes: 86 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,91 @@
# react-native-phone-picker

# 我的扩展

## 扩展Android 实现

- 动态申请权限
- 在Android的CallBack中,是3个参数

```js
error{
0:成功,
1:权限被拒绝,
2:权限被决绝,并不再询问,
3:未知错误
}
callback(phone,name,error){

}
```

- android api 最低版本 为19


## link-Android

关于方法数超限,已经移除多余无用的库,可能不会出现了,但是如果你引入了太多的android源生模块,可能还需要这么配置

- android/settings.gradle
```
include ':react-native-phone-picker'
project(':react-native-phone-picker').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-phone-picker/android/')
```
- android/app/build.gradle
```

android{
defaultConfig {
// 方法数超限
multiDexEnabled true
}
}

dependencies {
...
//添加
compile project(':react-native-phone-picker')
}
```

- MainApplication.java

```java
//添加
import android.support.multidex.MultiDexApplication;
//注意,方法数可能超限,
//将Application 改为 MultiDexApplication
public class MainApplication extends MultiDexApplication implements ReactApplication {


private final ReactNativeHost mReactNativeHost = new ReactNativeHost(this) {
@Override
public boolean getUseDeveloperSupport() {
return BuildConfig.DEBUG;
}

@Override
protected List<ReactPackage> getPackages() {
return Arrays.<ReactPackage>asList(
new MyReactPackage(),
//添加
new PhonePickerPackage()
);
}

@Override
protected String getJSMainModuleName() {
return "index";
}
};
}

```



# 原README

React Native component for select phone number from address book

用于React Native的通讯录手机号选取模块
Expand Down
24 changes: 24 additions & 0 deletions android/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
apply plugin: 'com.android.library'

android {
compileSdkVersion 26
buildToolsVersion "26.0.1"
defaultConfig {
minSdkVersion 19
targetSdkVersion 26
versionCode 2
versionName "1.1"
}

buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}

dependencies {
provided 'com.android.support:appcompat-v7:26.1.0'
provided "com.facebook.react:react-native:+"
}
21 changes: 21 additions & 0 deletions android/proguard-rules.pro
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Add project specific ProGuard rules here.
# You can control the set of applied configuration files using the
# proguardFiles setting in build.gradle.
#
# For more details, see
# http://developer.android.com/guide/developing/tools/proguard.html

# If your project uses WebView with JS, uncomment the following
# and specify the fully qualified class name to the JavaScript interface
# class:
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
# public *;
#}

# Uncomment this to preserve the line number information for
# debugging stack traces.
#-keepattributes SourceFile,LineNumberTable

# If you keep the line number information, uncomment this to
# hide the original source file name.
#-renamesourcefileattribute SourceFile
2 changes: 2 additions & 0 deletions android/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="cn.yzl.reactnative.phonepicker" />
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package cn.yzl.reactnative.phonepicker;

/**
* Created by YZL on 2018/6/2.
*/

public interface ErrorCode {
/**
* 成功
*/
int SUCCESS = 0;
/**
* 权限被拒绝
*/
int PERMISSON_FAIL = 1;
/**
* 权限被拒绝,并不再询问
*/
int PERMISSON_NOASK = 2;
/**
* 其他
*/
int OTHER = 2;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
/**
* 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
* <p>
* http://www.apache.org/licenses/LICENSE-2.0
* <p>
* 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.
*/

package cn.yzl.reactnative.phonepicker;

import android.app.Activity;
import android.app.FragmentManager;
import android.support.annotation.NonNull;

import com.facebook.react.bridge.Callback;

public class PhonePicker {

static final String TAG = "REACT_NATIVE_PHONE_PICKER";

PhonePickerFragment phonePickerFragment;

public PhonePicker(@NonNull Activity activity) {
phonePickerFragment = getRxPermissionsFragment(activity);
}

private PhonePickerFragment getRxPermissionsFragment(Activity activity) {
PhonePickerFragment phonePickerFragment = findRxPermissionsFragment(activity);
boolean isNewInstance = phonePickerFragment == null;
if (isNewInstance) {
phonePickerFragment = new PhonePickerFragment();
FragmentManager fragmentManager = activity.getFragmentManager();
fragmentManager
.beginTransaction()
.add(phonePickerFragment, TAG)
.commitAllowingStateLoss();
fragmentManager.executePendingTransactions();
}
return phonePickerFragment;
}

private PhonePickerFragment findRxPermissionsFragment(Activity activity) {
return (PhonePickerFragment) activity.getFragmentManager().findFragmentByTag(TAG);
}

public void setCallback(Callback callback) {
if (phonePickerFragment != null) {
this.phonePickerFragment.setCallBack(callback);
}
}

public void startPicker() {
if (phonePickerFragment == null
|| phonePickerFragment.isDetached()) {
return;
}
phonePickerFragment.startPicker();
}
}
Loading