Skip to content

Commit

Permalink
feat(android): viewShadowColor parity (#13457)
Browse files Browse the repository at this point in the history
* feat(android): viewShadowColor parity

* change wording
  • Loading branch information
m1ga committed May 28, 2022
1 parent e6a8f43 commit 63b70fd
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -796,6 +796,7 @@ public class TiC
public static final String PROPERTY_VISIBILITY = "visibility";
public static final String PROPERTY_VISIBLE_ITEM_COUNT = "visibleItemCount";
public static final String PROPERTY_VIEW = "view";
public static final String PROPERTY_VIEW_SHADOW_COLOR = "viewShadowColor";
public static final String PROPERTY_VIEWS = "views";
public static final String PROPERTY_VOLUME = "volume";
public static final String PROPERTY_WAKE_LOCK = "wakeLock";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@
TiC.PROPERTY_SOFT_KEYBOARD_ON_FOCUS,
TiC.PROPERTY_TRANSFORM,
TiC.PROPERTY_ELEVATION,
TiC.PROPERTY_VIEW_SHADOW_COLOR,
TiC.PROPERTY_TRANSLATION_X,
TiC.PROPERTY_TRANSLATION_Y,
TiC.PROPERTY_TRANSLATION_Z,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -951,6 +951,17 @@ public void propertyChanged(String key, Object oldValue, Object newValue, KrollP
}
} else if (key.equals(TiC.PROPERTY_HIDDEN_BEHAVIOR)) {
hiddenBehavior = TiConvert.toInt(newValue, View.INVISIBLE);
} else if (key.equals(TiC.PROPERTY_VIEW_SHADOW_COLOR)) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
if (nativeView != null) {
nativeView.setOutlineAmbientShadowColor(TiConvert.toColor(TiConvert.toString(newValue),
TiApplication.getAppCurrentActivity()));
nativeView.setOutlineSpotShadowColor(TiConvert.toColor(TiConvert.toString(newValue),
TiApplication.getAppCurrentActivity()));
}
} else {
Log.w(TAG, "Setting the 'viewShadowColor' property requires Android P or later");
}
} else if (Log.isDebugModeEnabled()) {
Log.d(TAG, "Unhandled property key: " + key, Log.DEBUG_MODE);
}
Expand Down Expand Up @@ -1105,6 +1116,19 @@ public void processProperties(KrollDict d)
ViewCompat.setTranslationZ(nativeView, TiConvert.toFloat(d, TiC.PROPERTY_TRANSLATION_Z));
}

if (d.containsKey(TiC.PROPERTY_VIEW_SHADOW_COLOR) && !nativeViewNull) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
nativeView.setOutlineAmbientShadowColor(
TiConvert.toColor(TiConvert.toString(d, TiC.PROPERTY_VIEW_SHADOW_COLOR),
TiApplication.getAppCurrentActivity()));
nativeView.setOutlineSpotShadowColor(
TiConvert.toColor(TiConvert.toString(d, TiC.PROPERTY_VIEW_SHADOW_COLOR),
TiApplication.getAppCurrentActivity()));
} else {
Log.w(TAG, "Setting the 'viewShadowColor' property requires Android P or later");
}
}

if (!nativeViewNull && d.containsKeyAndNotNull(TiC.PROPERTY_TRANSITION_NAME)) {
ViewCompat.setTransitionName(nativeView, d.getString(TiC.PROPERTY_TRANSITION_NAME));
}
Expand Down
10 changes: 7 additions & 3 deletions apidoc/Titanium/UI/View.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1982,10 +1982,14 @@ properties:

- name: viewShadowColor
summary: Determines the color of the shadow.
description: Defaults to `undefined`. Behaves as if transparent.
description: |
iOS Defaults to `undefined`. Behaves as if transparent. Android default is black.
On Android you can set `<item name="android:ambientShadowAlpha">0.5</item>` and
`<item name="android:spotShadowAlpha">0.5</item>` in your theme to change the
opacity.
type: [String, Titanium.UI.Color]
platforms: [iphone, ipad, macos]
since: "3.3.0"
platforms: [android, iphone, ipad, macos]
since: {android: "11.1.0", iphone: "3.3.0", ipad: "3.3.0", macos: "9.2.0"}

- name: viewShadowOffset
summary: Determines the offset for the shadow of the view.
Expand Down

0 comments on commit 63b70fd

Please sign in to comment.