From 0389a3099e435d797d1aea7f83e146c2dc1f5396 Mon Sep 17 00:00:00 2001 From: m1ga Date: Sun, 9 Apr 2023 18:24:10 +0200 Subject: [PATCH 1/5] feat(android): maxWidth for Views --- .../titanium/view/TiBorderWrapperView.java | 20 +++++++++++++++++++ .../titanium/view/TiCompositeLayout.java | 9 +++++++++ .../appcelerator/titanium/view/TiUIView.java | 15 ++++++++++++++ apidoc/Titanium/UI/View.yml | 9 +++++++++ 4 files changed, 53 insertions(+) diff --git a/android/titanium/src/java/org/appcelerator/titanium/view/TiBorderWrapperView.java b/android/titanium/src/java/org/appcelerator/titanium/view/TiBorderWrapperView.java index 947b15de033..44b7c64f6b7 100644 --- a/android/titanium/src/java/org/appcelerator/titanium/view/TiBorderWrapperView.java +++ b/android/titanium/src/java/org/appcelerator/titanium/view/TiBorderWrapperView.java @@ -42,6 +42,7 @@ public class TiBorderWrapperView extends FrameLayout private Paint paint; private Rect bounds; private ViewOutlineProvider viewOutlineProvider; + private int viewMaxWidth = -1; public TiBorderWrapperView(Context context) { super(context); @@ -238,6 +239,20 @@ public void setRadius(Object obj) } } + /* + @Override + protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) + { + super.onMeasure(widthMeasureSpec, heightMeasureSpec); + int measuredWidth = widthMeasureSpec; + int measuredHeight = heightMeasureSpec; + if (viewMaxWidth != -1 && measuredWidth > viewMaxWidth) { + measuredWidth = viewMaxWidth; + } + setMeasuredDimension(measuredWidth, measuredHeight); + } + */ + public void setBorderWidth(float borderWidth) { this.borderWidth = borderWidth; @@ -248,4 +263,9 @@ public boolean onSetAlpha(int alpha) { return false; } + + public void setMaxWidth(int maxWidth) + { + viewMaxWidth = maxWidth; + } } diff --git a/android/titanium/src/java/org/appcelerator/titanium/view/TiCompositeLayout.java b/android/titanium/src/java/org/appcelerator/titanium/view/TiCompositeLayout.java index 7b59254c8b8..b75df2e9977 100644 --- a/android/titanium/src/java/org/appcelerator/titanium/view/TiCompositeLayout.java +++ b/android/titanium/src/java/org/appcelerator/titanium/view/TiCompositeLayout.java @@ -67,6 +67,7 @@ public enum LayoutArrangement { private boolean enableHorizontalWrap = true; private int horizontalLayoutLastIndexBeforeWrap = 0; private int horiztonalLayoutPreviousRight = 0; + private int viewMaxWidth = -1; int[] horizontal = new int[2]; int[] vertical = new int[2]; /** @@ -641,6 +642,9 @@ protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) int measuredWidth = getMeasuredWidth(maxWidth, widthMeasureSpec); int measuredHeight = getMeasuredHeight(maxHeight, heightMeasureSpec); + if (viewMaxWidth != -1 && measuredWidth > viewMaxWidth) { + measuredWidth = viewMaxWidth; + } setMeasuredDimension(measuredWidth, measuredHeight); } @@ -1237,6 +1241,11 @@ public void setLayoutArrangement(String arrangementProperty) } } + public void setMaxWidth(Integer maxWidth) + { + viewMaxWidth = maxWidth; + } + public void setEnableHorizontalWrap(boolean enable) { enableHorizontalWrap = enable; diff --git a/android/titanium/src/java/org/appcelerator/titanium/view/TiUIView.java b/android/titanium/src/java/org/appcelerator/titanium/view/TiUIView.java index ac0541d1344..129bdb15f15 100644 --- a/android/titanium/src/java/org/appcelerator/titanium/view/TiUIView.java +++ b/android/titanium/src/java/org/appcelerator/titanium/view/TiUIView.java @@ -111,6 +111,7 @@ public abstract class TiUIView implements KrollProxyListener, OnFocusChangeListe protected LayoutParams layoutParams; protected TiAnimationBuilder animBuilder; protected TiBackgroundDrawable background; + private int maxWidth = -1; public TiBackgroundDrawable getBackground() { @@ -1054,6 +1055,19 @@ public void processProperties(KrollDict d) nativeView.setEnabled(TiConvert.toBoolean(d, TiC.PROPERTY_ENABLED, true)); } + if (d.containsKey("maxWidth")) { + maxWidth = -1; + if (d.get("maxWidth") != null) { + maxWidth = d.getInt("maxWidth"); + maxWidth = TiConvert.toTiDimension(maxWidth, TiDimension.TYPE_WIDTH).getAsPixels(nativeView); + } + if (!hasBorder(d)) { + ((TiCompositeLayout) nativeView).setMaxWidth(maxWidth); + } else { + Log.w(TAG, "You can only use maxWidth for Views without borders"); + } + } + initializeBorder(d, bgColor); if (d.containsKey(TiC.PROPERTY_OPACITY) && !nativeViewNull) { @@ -1499,6 +1513,7 @@ private void initializeBorder(KrollDict d, Integer bgColor) currentActivity = TiApplication.getAppCurrentActivity(); } borderView = new TiBorderWrapperView(currentActivity); + //borderView.setMaxWidth(maxWidth); // TODO fix borderView maxWidth // Create new layout params for the child view since we just want the // wrapper to control the layout LayoutParams params = new LayoutParams(); diff --git a/apidoc/Titanium/UI/View.yml b/apidoc/Titanium/UI/View.yml index 005303f9db9..cdbe84458fe 100644 --- a/apidoc/Titanium/UI/View.yml +++ b/apidoc/Titanium/UI/View.yml @@ -2018,6 +2018,15 @@ properties: type: [Number,String] constants: [Titanium.UI.FILL, Titanium.UI.SIZE] + - name: maxWidth + summary: Maximum width of the View, in platform-specific units. + description: | + You can use the setting in combination with `width: Ti.UI.FILL` to set a maximum width. + The view won't extend the `maxWidth` value. + type: Number + since: {android: "12.2.0"} + platforms: [android] + - name: horizontalWrap summary: Determines whether the layout has wrapping behavior. description: | From 2b1c2afadef08b6839629572c4f9650b08b27f1b Mon Sep 17 00:00:00 2001 From: m1ga Date: Tue, 11 Apr 2023 15:08:49 +0200 Subject: [PATCH 2/5] feat(android): maxHeight --- .../titanium/view/TiCompositeLayout.java | 13 ++++- .../appcelerator/titanium/view/TiUIView.java | 50 +++++++++++++++---- apidoc/Titanium/UI/View.yml | 9 ++++ 3 files changed, 59 insertions(+), 13 deletions(-) diff --git a/android/titanium/src/java/org/appcelerator/titanium/view/TiCompositeLayout.java b/android/titanium/src/java/org/appcelerator/titanium/view/TiCompositeLayout.java index b75df2e9977..86fbc942d2e 100644 --- a/android/titanium/src/java/org/appcelerator/titanium/view/TiCompositeLayout.java +++ b/android/titanium/src/java/org/appcelerator/titanium/view/TiCompositeLayout.java @@ -68,6 +68,7 @@ public enum LayoutArrangement { private int horizontalLayoutLastIndexBeforeWrap = 0; private int horiztonalLayoutPreviousRight = 0; private int viewMaxWidth = -1; + private int viewMaxHeight = -1; int[] horizontal = new int[2]; int[] vertical = new int[2]; /** @@ -645,6 +646,9 @@ protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) if (viewMaxWidth != -1 && measuredWidth > viewMaxWidth) { measuredWidth = viewMaxWidth; } + if (viewMaxHeight != -1 && measuredHeight > viewMaxHeight) { + measuredHeight = viewMaxHeight; + } setMeasuredDimension(measuredWidth, measuredHeight); } @@ -1241,9 +1245,14 @@ public void setLayoutArrangement(String arrangementProperty) } } - public void setMaxWidth(Integer maxWidth) + public void setMaxWidth(Integer value) + { + viewMaxWidth = value; + } + + public void setMaxHeight(Integer value) { - viewMaxWidth = maxWidth; + viewMaxHeight = value; } public void setEnableHorizontalWrap(boolean enable) diff --git a/android/titanium/src/java/org/appcelerator/titanium/view/TiUIView.java b/android/titanium/src/java/org/appcelerator/titanium/view/TiUIView.java index 129bdb15f15..1ecd4fa33a5 100644 --- a/android/titanium/src/java/org/appcelerator/titanium/view/TiUIView.java +++ b/android/titanium/src/java/org/appcelerator/titanium/view/TiUIView.java @@ -112,6 +112,7 @@ public abstract class TiUIView implements KrollProxyListener, OnFocusChangeListe protected TiAnimationBuilder animBuilder; protected TiBackgroundDrawable background; private int maxWidth = -1; + private int maxHeight = -1; public TiBackgroundDrawable getBackground() { @@ -785,6 +786,10 @@ public void propertyChanged(String key, Object oldValue, Object newValue, KrollP doSetClickable(TiConvert.toBoolean(newValue)); } else if (key.equals(TiC.PROPERTY_FILTER_TOUCHES_WHEN_OBSCURED)) { setFilterTouchesWhenObscured(TiConvert.toBoolean(newValue, false)); + } else if (key.equals("maxWidth")) { + setMaxWidth(newValue, hasBorder(proxy.getProperties())); + } else if (key.equals("maxHeight")) { + setMaxHeight(newValue, hasBorder(proxy.getProperties())); } else if (key.equals(TiC.PROPERTY_VISIBLE)) { newValue = (newValue == null) ? false : newValue; this.setVisibility(TiConvert.toBoolean(newValue) ? View.VISIBLE : View.INVISIBLE); @@ -1056,18 +1061,11 @@ public void processProperties(KrollDict d) } if (d.containsKey("maxWidth")) { - maxWidth = -1; - if (d.get("maxWidth") != null) { - maxWidth = d.getInt("maxWidth"); - maxWidth = TiConvert.toTiDimension(maxWidth, TiDimension.TYPE_WIDTH).getAsPixels(nativeView); - } - if (!hasBorder(d)) { - ((TiCompositeLayout) nativeView).setMaxWidth(maxWidth); - } else { - Log.w(TAG, "You can only use maxWidth for Views without borders"); - } + setMaxWidth(d.get("maxWidth"), hasBorder(d)); + } + if (d.containsKey("maxHeight")) { + setMaxHeight(d.get("maxHeight"), hasBorder(d)); } - initializeBorder(d, bgColor); if (d.containsKey(TiC.PROPERTY_OPACITY) && !nativeViewNull) { @@ -1157,6 +1155,36 @@ public void processProperties(KrollDict d) } } + private void setMaxWidth(Object value, Boolean hasBorder) + { + maxWidth = -1; + if (value != null) { + maxWidth = TiConvert.toTiDimension(TiConvert.toInt(value), + TiDimension.TYPE_WIDTH).getAsPixels(nativeView); + } + + if (!hasBorder) { + ((TiCompositeLayout) nativeView).setMaxWidth(maxWidth); + } else { + Log.w(TAG, "You can only use maxWidth for Views without borders"); + } + } + + private void setMaxHeight(Object value, Boolean hasBorder) + { + maxHeight = -1; + if (value != null) { + maxHeight = TiConvert.toTiDimension(TiConvert.toInt(value), + TiDimension.TYPE_HEIGHT).getAsPixels(nativeView); + } + + if (!hasBorder) { + ((TiCompositeLayout) nativeView).setMaxHeight(maxHeight); + } else { + Log.w(TAG, "You can only use maxHeight for Views without borders"); + } + } + private void setAnchor(HashMap point) { View outerView = getOuterView(); diff --git a/apidoc/Titanium/UI/View.yml b/apidoc/Titanium/UI/View.yml index cdbe84458fe..ec1bbb7acf5 100644 --- a/apidoc/Titanium/UI/View.yml +++ b/apidoc/Titanium/UI/View.yml @@ -2027,6 +2027,15 @@ properties: since: {android: "12.2.0"} platforms: [android] + - name: maxHeight + summary: Maximum height of the View, in platform-specific units. + description: | + You can use the setting in combination with `height: Ti.UI.FILL` to set a maximum height. + The view won't extend the `maxHeight` value. + type: Number + since: {android: "12.2.0"} + platforms: [android] + - name: horizontalWrap summary: Determines whether the layout has wrapping behavior. description: | From 109b7df47ae99ce1863c2919d32d08bb755dfbb6 Mon Sep 17 00:00:00 2001 From: Michael Gangolf Date: Sat, 4 May 2024 01:21:02 +0200 Subject: [PATCH 3/5] minWidth --- .../titanium/view/TiCompositeLayout.java | 8 +++++++ .../appcelerator/titanium/view/TiUIView.java | 21 +++++++++++++++++++ 2 files changed, 29 insertions(+) diff --git a/android/titanium/src/java/org/appcelerator/titanium/view/TiCompositeLayout.java b/android/titanium/src/java/org/appcelerator/titanium/view/TiCompositeLayout.java index 86fbc942d2e..f671eb3ce11 100644 --- a/android/titanium/src/java/org/appcelerator/titanium/view/TiCompositeLayout.java +++ b/android/titanium/src/java/org/appcelerator/titanium/view/TiCompositeLayout.java @@ -67,6 +67,7 @@ public enum LayoutArrangement { private boolean enableHorizontalWrap = true; private int horizontalLayoutLastIndexBeforeWrap = 0; private int horiztonalLayoutPreviousRight = 0; + private int viewMinWidth = -1; private int viewMaxWidth = -1; private int viewMaxHeight = -1; int[] horizontal = new int[2]; @@ -646,6 +647,9 @@ protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) if (viewMaxWidth != -1 && measuredWidth > viewMaxWidth) { measuredWidth = viewMaxWidth; } + if (viewMinWidth != -1 && measuredWidth < viewMinWidth) { + measuredWidth = viewMinWidth; + } if (viewMaxHeight != -1 && measuredHeight > viewMaxHeight) { measuredHeight = viewMaxHeight; } @@ -1250,6 +1254,10 @@ public void setMaxWidth(Integer value) viewMaxWidth = value; } + public void setMinWidth(Integer value) + { + viewMinWidth = value; + } public void setMaxHeight(Integer value) { viewMaxHeight = value; diff --git a/android/titanium/src/java/org/appcelerator/titanium/view/TiUIView.java b/android/titanium/src/java/org/appcelerator/titanium/view/TiUIView.java index 1ecd4fa33a5..fffcf0c891b 100644 --- a/android/titanium/src/java/org/appcelerator/titanium/view/TiUIView.java +++ b/android/titanium/src/java/org/appcelerator/titanium/view/TiUIView.java @@ -111,6 +111,7 @@ public abstract class TiUIView implements KrollProxyListener, OnFocusChangeListe protected LayoutParams layoutParams; protected TiAnimationBuilder animBuilder; protected TiBackgroundDrawable background; + private int minWidth = -1; private int maxWidth = -1; private int maxHeight = -1; @@ -788,6 +789,8 @@ public void propertyChanged(String key, Object oldValue, Object newValue, KrollP setFilterTouchesWhenObscured(TiConvert.toBoolean(newValue, false)); } else if (key.equals("maxWidth")) { setMaxWidth(newValue, hasBorder(proxy.getProperties())); + } else if (key.equals("minWidth")) { + setMinWidth(newValue, hasBorder(proxy.getProperties())); } else if (key.equals("maxHeight")) { setMaxHeight(newValue, hasBorder(proxy.getProperties())); } else if (key.equals(TiC.PROPERTY_VISIBLE)) { @@ -1063,6 +1066,9 @@ public void processProperties(KrollDict d) if (d.containsKey("maxWidth")) { setMaxWidth(d.get("maxWidth"), hasBorder(d)); } + if (d.containsKey("minWidth")) { + setMinWidth(d.get("minWidth"), hasBorder(d)); + } if (d.containsKey("maxHeight")) { setMaxHeight(d.get("maxHeight"), hasBorder(d)); } @@ -1170,6 +1176,21 @@ private void setMaxWidth(Object value, Boolean hasBorder) } } + private void setMinWidth(Object value, Boolean hasBorder) + { + minWidth = -1; + if (value != null) { + minWidth = TiConvert.toTiDimension(TiConvert.toInt(value), + TiDimension.TYPE_WIDTH).getAsPixels(nativeView); + } + + if (!hasBorder) { + ((TiCompositeLayout) nativeView).setMinWidth(minWidth); + } else { + Log.w(TAG, "You can only use minWidth for Views without borders"); + } + } + private void setMaxHeight(Object value, Boolean hasBorder) { maxHeight = -1; From 1473b8b7bee990a5c21b3a8a828b428a030c207b Mon Sep 17 00:00:00 2001 From: Michael Gangolf Date: Sat, 4 May 2024 10:56:20 +0200 Subject: [PATCH 4/5] minHeight --- .../titanium/view/TiCompositeLayout.java | 8 ++++++++ .../appcelerator/titanium/view/TiUIView.java | 20 +++++++++++++++++++ 2 files changed, 28 insertions(+) diff --git a/android/titanium/src/java/org/appcelerator/titanium/view/TiCompositeLayout.java b/android/titanium/src/java/org/appcelerator/titanium/view/TiCompositeLayout.java index 7df21356180..2c22bd0970c 100644 --- a/android/titanium/src/java/org/appcelerator/titanium/view/TiCompositeLayout.java +++ b/android/titanium/src/java/org/appcelerator/titanium/view/TiCompositeLayout.java @@ -70,6 +70,7 @@ public enum LayoutArrangement { private int viewMinWidth = -1; private int viewMaxWidth = -1; private int viewMaxHeight = -1; + private int viewMinHeight = -1; int[] horizontal = new int[2]; int[] vertical = new int[2]; /** @@ -653,6 +654,9 @@ protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) if (viewMaxHeight != -1 && measuredHeight > viewMaxHeight) { measuredHeight = viewMaxHeight; } + if (viewMinHeight != -1 && measuredHeight < viewMinHeight) { + measuredHeight = viewMinHeight; + } setMeasuredDimension(measuredWidth, measuredHeight); } @@ -1262,6 +1266,10 @@ public void setMaxHeight(Integer value) { viewMaxHeight = value; } + public void setMinHeight(Integer value) + { + viewMinHeight = value; + } public void setEnableHorizontalWrap(boolean enable) { diff --git a/android/titanium/src/java/org/appcelerator/titanium/view/TiUIView.java b/android/titanium/src/java/org/appcelerator/titanium/view/TiUIView.java index a50adba4fd7..56cd0087073 100644 --- a/android/titanium/src/java/org/appcelerator/titanium/view/TiUIView.java +++ b/android/titanium/src/java/org/appcelerator/titanium/view/TiUIView.java @@ -113,6 +113,7 @@ public abstract class TiUIView implements KrollProxyListener, OnFocusChangeListe protected TiBackgroundDrawable background; private int minWidth = -1; private int maxWidth = -1; + private int minHeight = -1; private int maxHeight = -1; public TiBackgroundDrawable getBackground() @@ -793,6 +794,8 @@ public void propertyChanged(String key, Object oldValue, Object newValue, KrollP setMinWidth(newValue, hasBorder(proxy.getProperties())); } else if (key.equals("maxHeight")) { setMaxHeight(newValue, hasBorder(proxy.getProperties())); + } else if (key.equals("minHeight")) { + setMinHeight(newValue, hasBorder(proxy.getProperties())); } else if (key.equals(TiC.PROPERTY_VISIBLE)) { newValue = (newValue == null) ? false : newValue; this.setVisibility(TiConvert.toBoolean(newValue) ? View.VISIBLE : View.INVISIBLE); @@ -1072,6 +1075,9 @@ public void processProperties(KrollDict d) if (d.containsKey("maxHeight")) { setMaxHeight(d.get("maxHeight"), hasBorder(d)); } + if (d.containsKey("minHeight")) { + setMinHeight(d.get("minHeight"), hasBorder(d)); + } initializeBorder(d, bgColor); if (d.containsKey(TiC.PROPERTY_OPACITY) && !nativeViewNull) { @@ -1205,6 +1211,20 @@ private void setMaxHeight(Object value, Boolean hasBorder) Log.w(TAG, "You can only use maxHeight for Views without borders"); } } + private void setMinHeight(Object value, Boolean hasBorder) + { + minHeight = -1; + if (value != null) { + minHeight = TiConvert.toTiDimension(TiConvert.toInt(value), + TiDimension.TYPE_HEIGHT).getAsPixels(nativeView); + } + + if (!hasBorder) { + ((TiCompositeLayout) nativeView).setMinHeight(minHeight); + } else { + Log.w(TAG, "You can only use maxHeight for Views without borders"); + } + } private void setAnchor(HashMap point) { From f1ebe8a44df974774ccf003cf5164492f7657dbf Mon Sep 17 00:00:00 2001 From: Michael Gangolf Date: Sat, 4 May 2024 11:12:30 +0200 Subject: [PATCH 5/5] apidoc --- apidoc/Titanium/UI/View.yml | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/apidoc/Titanium/UI/View.yml b/apidoc/Titanium/UI/View.yml index 7398f28eb43..d2360fa0dd8 100644 --- a/apidoc/Titanium/UI/View.yml +++ b/apidoc/Titanium/UI/View.yml @@ -1957,7 +1957,7 @@ properties: You can use the setting in combination with `width: Ti.UI.FILL` to set a maximum width. The view won't extend the `maxWidth` value. type: Number - since: {android: "12.2.0"} + since: {android: "12.4.0"} platforms: [android] - name: maxHeight @@ -1966,7 +1966,25 @@ properties: You can use the setting in combination with `height: Ti.UI.FILL` to set a maximum height. The view won't extend the `maxHeight` value. type: Number - since: {android: "12.2.0"} + since: {android: "12.4.0"} + platforms: [android] + + - name: minWidth + summary: Minimum width of the View, in platform-specific units. + description: | + You can use the setting in combination with `width: Ti.UI.SIZE` to set a minimum width. + The view won't be smaller than the `minWidth` value. + type: Number + since: {android: "12.4.0"} + platforms: [android] + + - name: minHeight + summary: Minimum height of the View, in platform-specific units. + description: | + You can use the setting in combination with `height: Ti.UI.SIZE` to set a minimum height. + The view won't be smaller than the `minHeight` value. + type: Number + since: {android: "12.4.0"} platforms: [android] - name: horizontalWrap