Skip to content
This repository has been archived by the owner on Jan 5, 2024. It is now read-only.

Commit

Permalink
[ANDROID] Refactoring of Code plus bug fixes (react-native-image-pick…
Browse files Browse the repository at this point in the history
…er#496)

* Fixed issue#485
Fixed issue#478

* Removed useless file

* Recoverd options for launchCamera and launchImageLibrary
  • Loading branch information
rusfearuth authored and marcshilling committed Mar 4, 2017
1 parent 0447415 commit 7eaa65d
Show file tree
Hide file tree
Showing 22 changed files with 606 additions and 148 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ xcuserdata/
### Node
node_modules
*.log
yarn.lock

## Android iml
*.iml
1 change: 1 addition & 0 deletions .npmignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
Example/
images/
node_modules/
2 changes: 1 addition & 1 deletion Example/android/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ android {
defaultConfig {
applicationId "com.example"
minSdkVersion 16
targetSdkVersion 23
targetSdkVersion 22
versionCode 1
versionName "1.0"
ndk {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public class MainApplication extends Application implements ReactApplication {

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

Expand Down
2 changes: 1 addition & 1 deletion Example/android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ buildscript {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.1.0'
classpath 'com.android.tools.build:gradle:2.2.+'

// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
Expand Down
2 changes: 1 addition & 1 deletion Example/android/gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-2.10-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-2.14.1-all.zip
4 changes: 2 additions & 2 deletions Example/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
},
"dependencies": {
"react": "15.4.1",
"react-native": "0.40.0",
"react-native-image-picker": "../"
"react-native": "^0.42.0",
"react-native-image-picker": "file:../"
}
}
86 changes: 82 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,20 +46,37 @@ IMPORTANT NOTE: You'll still need to perform step 4 for iOS and step 3 for Andro
include ':react-native-image-picker'
project(':react-native-image-picker').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-image-picker/android')
```
2. Add the compile line to the dependencies in `android/app/build.gradle`:
2. Update the android build tools version to `2.2.+` in `android/build.gradle`:
```gradle
buildscript {
...
dependencies {
classpath 'com.android.tools.build:gradle:2.2.+' // <- USE 2.2.+ version
}
...
}
...
```
3. Update the gradle version to `2.14.1` in `android/gradle/wrapper/gradle-wrapper.properties`:
```
...
distributionUrl=https\://services.gradle.org/distributions/gradle-2.14.1-all.zip
```
4. Add the compile line to the dependencies in `android/app/build.gradle`:
```gradle
dependencies {
compile project(':react-native-image-picker')
}
```
3. Add the required permissions in `AndroidManifest.xml`:
5. Add the required permissions in `AndroidManifest.xml`:
```xml
<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
```
4. Add the import and link the package in `MainApplication.java`:
6. Add the import and link the package in `MainApplication.java`:
```java
import com.imagepicker.ImagePickerPackage; // <-- add this import
Expand All @@ -70,10 +87,67 @@ IMPORTANT NOTE: You'll still need to perform step 4 for iOS and step 3 for Andro
return Arrays.<ReactPackage>asList(
new MainReactPackage(),
new ImagePickerPackage() // <-- add this line
// OR if you want to customize dialog style
new ImagePickerPackage(R.style.my_dialog_style)
);
}
}
```
```
Customization settings of dialog `android/app/res/values/themes.xml`:
```xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="DefaultExplainingPermissionsTheme" parent="Theme.AppCompat.Light.Dialog.Alert">
<!-- Used for the buttons -->
<item name="colorAccent">@color/your_color</item>
<!-- Used for the title and text -->
<item name="android:textColorPrimary">@color/your_color</item>
<!-- Used for the background -->
<item name="android:background">@color/your_color</item>
</style>
<resources>
```
##### Android (Optional)
If `MainActivity` is not instance of `ReactActivity`, you will need to implement `OnImagePickerPermissionsCallback` to `MainActivity`:
```java
import com.imagepicker.permissions.OnImagePickerPermissionsCallback; // <- add this import
import com.facebook.react.modules.core.PermissionListener; // <- add this import
public class MainActivity extends YourActivity implements OnImagePickerPermissionsCallback {
private PermissionListener listener; // <- add this attribute
// Your methods here
// Copy from here
@Override
public void setPermissionListener(PermissionListener listener)
{
this.listener = listener;
}
@Override
public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults)
{
if (listener != null)
{
listener.onRequestPermissionsResult(requestCode, permissions, grantResults);
}
super.onRequestPermissionsResult(requestCode, permissions, grantResults);
}
// To here
}
```
This code allows to pass result of request permissions to native part.
## Usage
Expand Down Expand Up @@ -169,6 +243,10 @@ storageOptions.skipBackup | OK | - | If true, the photo will NOT be backed up to
storageOptions.path | OK | - | If set, will save image at /Documents/[path] rather than the root
storageOptions.cameraRoll | OK | - | If true, the cropped photo will be saved to the iOS Camera Roll.
storageOptions.waitUntilSaved | OK | - | If true, will delay the response callback until after the photo/video was saved to the Camera Roll. If the photo or video was just taken, then the file name and timestamp fields are only provided in the response object when this is true.
permissionDenied.title | - | OK | Title of explaining permissions dialog. By default `Permission denied`.
permissionDenied.text | - | OK | Message of explaining permissions dialog. By default `To be able to take pictures with your camera and choose images from your library.`.
permissionDenied.reTryTitle | - | OK | Title of re-try button. By default `re-try`
permissionDenied.okTitle | - | OK | Title of ok button. By default `I'm sure`

### The Response Object

Expand Down
8 changes: 7 additions & 1 deletion android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ buildscript {
}

dependencies {
classpath 'com.android.tools.build:gradle:1.3.1'
classpath 'com.android.tools.build:gradle:2.2.+'
}
}

Expand All @@ -36,6 +36,12 @@ android {

repositories {
mavenCentral()
maven {
url "$projectDir/../Example/node_modules/react-native/android"
}
maven {
url "$projectDir/../../react-native/android"
}
}

dependencies {
Expand Down
2 changes: 1 addition & 1 deletion android/gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-2.2-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-2.14.1-all.zip
Loading

0 comments on commit 7eaa65d

Please sign in to comment.