-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
feat(android): add parity for BlurView API, move iOS to Ti.UI namespace #14277
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
Open
hansemannn
wants to merge
12
commits into
tidev:main
Choose a base branch
from
hansemannn:feature/android-blurview
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 9 commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
2c97ed2
feat(android): add parity for BlurView API
hansemannn 84a94c8
chore: address review feedback, fix warnings
hansemannn 2fc1a1e
refactor: move Ti.UI.iOS.BlurView to Ti.UI.BlurView
hansemannn bf4c6f1
chore: update docs
hansemannn 1ce6fd7
fix(android): properly handle white tint
hansemannn c43bee1
chore: do not remove BlurView iOS-only api in 13.0.0, but deprecate
hansemannn 24d5e91
chore: align docs regarding iOS-specific and cross-platform constants
hansemannn dfe35eb
chore: keep Ti.UI.iOS.BlurView API in 13.0.0 (remove in SDK 14.0.0)
hansemannn c3d176b
chore: add deprecation warning, remove duplicate code (it can referen…
hansemannn 10ddbcf
chore: add android note
hansemannn c096c4e
chore: remove jitpack and add src files
m1ga 508098f
Merge branch 'feature/android-blurview' of https://github.com/hansema…
m1ga File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
37 changes: 37 additions & 0 deletions
37
android/modules/ui/src/java/ti/modules/titanium/ui/BlurViewProxy.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,37 @@ | ||
| /** | ||
| * Titanium SDK | ||
| * Copyright TiDev, Inc. 04/07/2022-Present | ||
| * Licensed under the terms of the Apache Public License | ||
| * Please see the LICENSE included with this distribution for details. | ||
| */ | ||
| package ti.modules.titanium.ui; | ||
|
|
||
| import android.app.Activity; | ||
|
|
||
| import org.appcelerator.kroll.annotations.Kroll; | ||
| import org.appcelerator.titanium.proxy.TiViewProxy; | ||
| import org.appcelerator.titanium.view.TiUIView; | ||
|
|
||
| import ti.modules.titanium.ui.widget.TiUIBlurView; | ||
|
|
||
| @Kroll.proxy(creatableInModule = UIModule.class) | ||
| public class BlurViewProxy extends TiViewProxy | ||
| { | ||
| public BlurViewProxy() | ||
| { | ||
| super(); | ||
| } | ||
|
|
||
| @Override | ||
| public TiUIView createView(Activity activity) | ||
| { | ||
| return new TiUIBlurView(this); | ||
| } | ||
|
|
||
| @Override | ||
| public String getApiName() | ||
| { | ||
| return "Ti.UI.BlurView"; | ||
| } | ||
| } | ||
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
227 changes: 227 additions & 0 deletions
227
android/modules/ui/src/java/ti/modules/titanium/ui/widget/TiUIBlurView.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,227 @@ | ||
| /** | ||
| * Titanium SDK | ||
| * Copyright TiDev, Inc. 04/07/2022-Present | ||
| * Licensed under the terms of the Apache Public License | ||
| * Please see the LICENSE included with this distribution for details. | ||
| */ | ||
| package ti.modules.titanium.ui.widget; | ||
|
|
||
| import android.graphics.Color; | ||
| import android.graphics.drawable.ColorDrawable; | ||
| import android.graphics.drawable.Drawable; | ||
| import android.view.View; | ||
| import android.view.ViewGroup; | ||
| import android.widget.FrameLayout; | ||
|
|
||
| import org.appcelerator.kroll.KrollDict; | ||
| import org.appcelerator.kroll.KrollProxy; | ||
| import org.appcelerator.kroll.common.Log; | ||
| import org.appcelerator.titanium.TiC; | ||
| import org.appcelerator.titanium.proxy.TiViewProxy; | ||
| import org.appcelerator.titanium.util.TiConvert; | ||
| import org.appcelerator.titanium.view.TiCompositeLayout; | ||
| import org.appcelerator.titanium.view.TiUIView; | ||
|
|
||
| import androidx.annotation.Nullable; | ||
|
|
||
| import eightbitlab.com.blurview.BlurView; | ||
| import ti.modules.titanium.ui.UIModule; | ||
|
|
||
| public class TiUIBlurView extends TiUIView | ||
| { | ||
| private static final String TAG = "TiUIBlurView"; | ||
|
|
||
| // Custom property keys (Android-only) | ||
| private static final String PROPERTY_EFFECT = "effect"; // Number (Ti.UI.BLUR_EFFECT_STYLE_*) | ||
| private static final String PROPERTY_BLUR_RADIUS = "blurRadius"; // Number | ||
| private static final String PROPERTY_OVERLAY_COLOR = "overlayColor"; // String color | ||
|
|
||
| private final BlurView blurView; | ||
| private final TiCompositeLayout contentLayout; | ||
|
|
||
| // Current config | ||
| private float blurRadius = 16f; | ||
| private int overlayColor = 0x00FFFFFF; // transparent by default | ||
| private int effectStyle = -1; // unset | ||
|
|
||
| private class BlurContainer extends FrameLayout | ||
| { | ||
| final TiCompositeLayout layout; | ||
| final BlurView innerBlurView; | ||
|
|
||
| BlurContainer() | ||
| { | ||
| super(proxy.getActivity()); | ||
|
|
||
| // Determine arrangement from proxy | ||
| TiCompositeLayout.LayoutArrangement arrangement = TiCompositeLayout.LayoutArrangement.DEFAULT; | ||
| Object layoutValue = proxy.getProperty(TiC.PROPERTY_LAYOUT); | ||
| if (TiC.LAYOUT_VERTICAL.equals(layoutValue)) { | ||
| arrangement = TiCompositeLayout.LayoutArrangement.VERTICAL; | ||
| } else if (TiC.LAYOUT_HORIZONTAL.equals(layoutValue)) { | ||
| arrangement = TiCompositeLayout.LayoutArrangement.HORIZONTAL; | ||
| } | ||
|
|
||
| // Create blur and content layout | ||
| innerBlurView = new BlurView(proxy.getActivity()); | ||
| innerBlurView.setLayoutParams(new FrameLayout.LayoutParams( | ||
| ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT)); | ||
|
|
||
| layout = new TiCompositeLayout(proxy.getActivity(), arrangement, proxy); | ||
| layout.setLayoutParams(new FrameLayout.LayoutParams( | ||
| ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT)); | ||
|
|
||
| // Add in order: blur background then content overlay | ||
| super.addView(innerBlurView); | ||
| super.addView(layout); | ||
| } | ||
|
|
||
| TiCompositeLayout getLayout() | ||
| { | ||
| return layout; | ||
| } | ||
|
|
||
| BlurView getBlurView() | ||
| { | ||
| return innerBlurView; | ||
| } | ||
|
|
||
| @Override | ||
| public void addView(View child, ViewGroup.LayoutParams params) | ||
| { | ||
| // Route adds to TiCompositeLayout to ensure correct LayoutParams | ||
| layout.addView(child, params); | ||
| } | ||
| } | ||
|
|
||
| public TiUIBlurView(TiViewProxy proxy) | ||
| { | ||
| super(proxy); | ||
|
|
||
| BlurContainer container = new BlurContainer(); | ||
| this.blurView = container.getBlurView(); | ||
| this.contentLayout = container.getLayout(); | ||
|
|
||
| setNativeView(container); | ||
| // Defer setup until we know the target (if provided) | ||
| setupOrUpdateBlur(); | ||
| } | ||
|
|
||
| @Override | ||
| public void processProperties(KrollDict d) | ||
| { | ||
| super.processProperties(d); | ||
|
|
||
| if (d.containsKey(PROPERTY_BLUR_RADIUS)) { | ||
| this.blurRadius = TiConvert.toFloat(d, PROPERTY_BLUR_RADIUS, this.blurRadius); | ||
| } | ||
| if (d.containsKey(PROPERTY_OVERLAY_COLOR)) { | ||
| this.overlayColor = TiConvert.toColor(d.get(PROPERTY_OVERLAY_COLOR), proxy.getActivity()); | ||
| } | ||
| if (d.containsKey(PROPERTY_EFFECT)) { | ||
| this.effectStyle = TiConvert.toInt(d.get(PROPERTY_EFFECT), -1); | ||
| applyEffectPresetIfAny(); | ||
| } | ||
|
|
||
| setupOrUpdateBlur(); | ||
| } | ||
|
|
||
| @Override | ||
| public void propertyChanged(String key, Object oldValue, Object newValue, KrollProxy proxy) | ||
| { | ||
| if (Log.isDebugModeEnabled()) { | ||
| Log.d(TAG, "Property changed: " + key + ", new: " + newValue, Log.DEBUG_MODE); | ||
| } | ||
|
|
||
| if (PROPERTY_BLUR_RADIUS.equals(key)) { | ||
| this.blurRadius = TiConvert.toFloat(newValue, this.blurRadius); | ||
| if (blurView != null) { | ||
| blurView.setBlurRadius(this.blurRadius); | ||
| } | ||
| } else if (PROPERTY_OVERLAY_COLOR.equals(key)) { | ||
| this.overlayColor = TiConvert.toColor(newValue, proxy.getActivity()); | ||
| if (blurView != null) { | ||
| blurView.setOverlayColor(this.overlayColor); | ||
| } | ||
| } else if (PROPERTY_EFFECT.equals(key)) { | ||
| this.effectStyle = TiConvert.toInt(newValue, -1); | ||
| applyEffectPresetIfAny(); | ||
| if (blurView != null) { | ||
| blurView.setOverlayColor(this.overlayColor); | ||
| blurView.setBlurRadius(this.blurRadius); | ||
| } | ||
| } else { | ||
| super.propertyChanged(key, oldValue, newValue, proxy); | ||
| } | ||
| } | ||
|
|
||
| private void setupOrUpdateBlur() | ||
| { | ||
| if (blurView == null) { | ||
| return; | ||
| } | ||
|
|
||
| Drawable windowBackground = getWindowBackground(); | ||
| if (windowBackground == null) { | ||
| windowBackground = new ColorDrawable(Color.TRANSPARENT); | ||
| } | ||
|
|
||
| // Legacy API: setup with root content view, using RenderScriptBlur for <31 | ||
| ViewGroup rootView = getRootContentView(); | ||
| if (rootView == null) { | ||
| return; | ||
| } | ||
|
|
||
| blurView.setupWith(rootView) | ||
| .setFrameClearDrawable(windowBackground) | ||
| .setBlurRadius(this.blurRadius) | ||
| .setOverlayColor(this.overlayColor); | ||
| } | ||
|
|
||
| private void applyEffectPresetIfAny() | ||
| { | ||
| // Map iOS-like styles to Android parameters. | ||
| // These constants are defined on Ti.UI.* | ||
| // Default values already set on fields. | ||
| switch (this.effectStyle) { | ||
| case UIModule.BLUR_EFFECT_STYLE_EXTRA_LIGHT: | ||
| this.blurRadius = 16f; | ||
| this.overlayColor = 0x66FFFFFF; // strongest white tint | ||
| break; | ||
| case UIModule.BLUR_EFFECT_STYLE_LIGHT: | ||
| this.blurRadius = 16f; | ||
| this.overlayColor = 0x44FFFFFF; // medium white tint | ||
| break; | ||
| case UIModule.BLUR_EFFECT_STYLE_DARK: | ||
| this.blurRadius = 16f; | ||
| this.overlayColor = 0x66000000; // dark tint | ||
| break; | ||
| default: | ||
| // leave custom values as-is when unknown | ||
| break; | ||
| } | ||
| } | ||
|
|
||
| @Nullable | ||
| private ViewGroup getRootContentView() | ||
| { | ||
| if (proxy == null || proxy.getActivity() == null || proxy.getActivity().getWindow() == null) { | ||
| return null; | ||
| } | ||
| View decor = proxy.getActivity().getWindow().getDecorView(); | ||
| View content = decor.findViewById(android.R.id.content); | ||
| if (content instanceof ViewGroup) { | ||
| return (ViewGroup) content; | ||
| } | ||
| return null; | ||
| } | ||
|
|
||
| @Nullable | ||
| private Drawable getWindowBackground() | ||
| { | ||
| if (proxy == null || proxy.getActivity() == null || proxy.getActivity().getWindow() == null) { | ||
| return null; | ||
| } | ||
| return proxy.getActivity().getWindow().getDecorView().getBackground(); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.