Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed Android #173

Merged
merged 2 commits into from
Apr 11, 2017
Merged
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
26 changes: 25 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,16 @@ Check the [roadmap here](https://github.com/Kureev/react-native-blur/issues/1)
3. (Android only) Add the following to your `android/app/build.gradle`

`android/build.gradle`
```
```
buildscript {
dependencies {
// Update "Android Plugin for Gradle" version
classpath 'com.android.tools.build:gradle:2.2.3'
}
}

// ...

allprojects {
repositories {
maven { url 'https://github.com/500px/500px-android-blur/raw/master/releases/' }
Expand All @@ -41,6 +50,21 @@ Check the [roadmap here](https://github.com/Kureev/react-native-blur/issues/1)
dependencies {
compile 'com.fivehundredpx:blurringview:1.0.0'
}


android {
defaultConfig {
// Add these to the existing config
renderscriptTargetApi 23
renderscriptSupportModeEnabled true
}
}
```

`android/gradle/wrapper/gradle-wrapper.properties`
```
// Update Gradle version
distributionUrl=https\://services.gradle.org/distributions/gradle-3.3-all.zip
```

4. Inside your code include JS part by adding
Expand Down
4 changes: 2 additions & 2 deletions android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,6 @@ repositories {
}

dependencies {
compile 'com.facebook.react:react-native:0.19.+'
compile 'com.facebook.react:react-native:0.41.+'
compile 'com.fivehundredpx:blurringview:1.0.0'
}
}
14 changes: 9 additions & 5 deletions android/src/main/java/com/cmcewen/blurview/BlurViewManager.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.cmcewen.blurview;

import android.app.Activity;
import android.view.View;
import android.view.ViewGroup;

Expand All @@ -14,13 +15,17 @@ public class BlurViewManager extends SimpleViewManager<BlurringView> {
public static final int defaultRadius = 10;
public static final int defaultSampling = 10;

private static Activity currentActivity;

@Override
public String getName() {
return REACT_CLASS;
}

@Override
public BlurringView createViewInstance(ThemedReactContext context) {
currentActivity = context.getCurrentActivity();

BlurringView blurringView = new BlurringView(context);
blurringView.setBlurRadius(defaultRadius);
blurringView.setDownsampleFactor(defaultSampling);
Expand All @@ -44,12 +49,11 @@ public void setDownsampleFactor(BlurringView view, int factor) {

@ReactProp(name = "viewRef")
public void setViewRef(BlurringView view, int viewRef) {
ViewGroup viewGroup = (ViewGroup) view.getRootView().findViewById(viewRef);
if (viewGroup != null) {
View v = viewGroup.getChildAt(0);
view.setBlurredView(v);
View blurredView = currentActivity.findViewById(viewRef);

if (blurredView != null) {
view.setBlurredView(blurredView);
view.invalidate();
}
}
}