From 387d6be1db0b2e047e20ab200048325de4a969e6 Mon Sep 17 00:00:00 2001 From: Joshua Quick Date: Tue, 23 Feb 2021 21:37:28 -0800 Subject: [PATCH] feat: add animation support to Ti.UI.ProgressBar Fixes TIMOB-28367 --- .../modules/titanium/ui/ProgressBarProxy.java | 2 ++ .../titanium/ui/widget/TiUIProgressBar.java | 5 ++-- apidoc/Titanium/UI/ProgressBar.yml | 6 +++++ iphone/Classes/TiUIProgressBar.h | 2 +- iphone/Classes/TiUIProgressBar.m | 8 ++++++- iphone/Classes/TiUIProgressBarProxy.m | 6 +++++ tests/Resources/ti.ui.progressbar.test.js | 23 +++++++++++++++++++ 7 files changed, 48 insertions(+), 4 deletions(-) diff --git a/android/modules/ui/src/java/ti/modules/titanium/ui/ProgressBarProxy.java b/android/modules/ui/src/java/ti/modules/titanium/ui/ProgressBarProxy.java index b381557df85..93e0c562732 100644 --- a/android/modules/ui/src/java/ti/modules/titanium/ui/ProgressBarProxy.java +++ b/android/modules/ui/src/java/ti/modules/titanium/ui/ProgressBarProxy.java @@ -16,6 +16,7 @@ @Kroll.proxy(creatableInModule = UIModule.class, propertyAccessors = { + TiC.PROPERTY_ANIMATED, TiC.PROPERTY_MIN, TiC.PROPERTY_MAX, TiC.PROPERTY_VALUE, @@ -29,6 +30,7 @@ public class ProgressBarProxy extends TiViewProxy public ProgressBarProxy() { super(); + defaultValues.put(TiC.PROPERTY_ANIMATED, true); } @Override diff --git a/android/modules/ui/src/java/ti/modules/titanium/ui/widget/TiUIProgressBar.java b/android/modules/ui/src/java/ti/modules/titanium/ui/widget/TiUIProgressBar.java index 721b94953f5..daeb9c17878 100644 --- a/android/modules/ui/src/java/ti/modules/titanium/ui/widget/TiUIProgressBar.java +++ b/android/modules/ui/src/java/ti/modules/titanium/ui/widget/TiUIProgressBar.java @@ -40,7 +40,7 @@ protected void onLayout(boolean changed, int left, int top, int right, int botto view.setOrientation(LinearLayout.VERTICAL); label = new MaterialTextView(proxy.getActivity()); label.setGravity(Gravity.TOP | Gravity.START); - label.setPadding(0, 0, 0, 0); + label.setPadding(0, 0, 0, 4); label.setSingleLine(false); progress = new LinearProgressIndicator(proxy.getActivity()); @@ -135,7 +135,8 @@ private int convertRange(double min, double max, double value, int base) public void updateProgress() { - progress.setProgress(convertRange(getMin(), getMax(), getValue(), 1000)); + boolean isAnimated = TiConvert.toBoolean(proxy.getProperty(TiC.PROPERTY_ANIMATED), true); + progress.setProgressCompat(convertRange(getMin(), getMax(), getValue(), 1000), isAnimated); } public void handleSetMessage(String message) diff --git a/apidoc/Titanium/UI/ProgressBar.yml b/apidoc/Titanium/UI/ProgressBar.yml index 741dea0d77b..cbe50f8c92b 100644 --- a/apidoc/Titanium/UI/ProgressBar.yml +++ b/apidoc/Titanium/UI/ProgressBar.yml @@ -32,6 +32,12 @@ excludes: properties: [children] methods: [add, remove, removeAllChildren, replaceAt] properties: + - name: animated + summary: Enables smooth progress change animation when changing the value. + type: Boolean + default: true + since: "10.0.0" + - name: color summary: Color of the progress bar message, as a color name or hex triplet. description: | diff --git a/iphone/Classes/TiUIProgressBar.h b/iphone/Classes/TiUIProgressBar.h index c2a9a234d44..e63d8d6d8cf 100644 --- a/iphone/Classes/TiUIProgressBar.h +++ b/iphone/Classes/TiUIProgressBar.h @@ -15,7 +15,7 @@ UIProgressViewStyle style; CGFloat max; CGFloat min; - + BOOL animated; UILabel *messageLabel; #ifdef TI_USE_AUTOLAYOUT diff --git a/iphone/Classes/TiUIProgressBar.m b/iphone/Classes/TiUIProgressBar.m index 1fd168355f6..e2a8008a759 100644 --- a/iphone/Classes/TiUIProgressBar.m +++ b/iphone/Classes/TiUIProgressBar.m @@ -27,6 +27,7 @@ - (id)initWithStyle:(UIProgressViewStyle)_style andMinimumValue:(CGFloat)_min ma style = _style; min = _min; max = _max; + animated = [TiUtils boolValue:[self.proxy valueForKey:@"animated"] def:YES]; [self setHidden:YES]; #ifdef TI_USE_AUTOLAYOUT @@ -148,6 +149,11 @@ - (void)layoutSubviews #pragma mark Properties +- (void)setAnimated_:(id)value +{ + animated = [TiUtils boolValue:value]; +} + - (void)setMin_:(id)value { min = [TiUtils floatValue:value]; @@ -161,7 +167,7 @@ - (void)setMax_:(id)value - (void)setValue_:(id)value { CGFloat newValue = ([TiUtils floatValue:value] - min) / (max - min); - [[self progress] setProgress:newValue]; + [[self progress] setProgress:newValue animated:animated]; } - (void)setFont_:(id)value diff --git a/iphone/Classes/TiUIProgressBarProxy.m b/iphone/Classes/TiUIProgressBarProxy.m index 5c2b55a5d34..4e6f4ed7be0 100644 --- a/iphone/Classes/TiUIProgressBarProxy.m +++ b/iphone/Classes/TiUIProgressBarProxy.m @@ -20,6 +20,12 @@ - (NSString *)apiName return @"Ti.UI.ProgressBar"; } +- (void)_initWithProperties:(NSDictionary *)properties +{ + [self initializeProperty:@"animated" defaultValue:NUMBOOL(YES)]; + [super _initWithProperties:properties]; +} + - (TiUIView *)newView { UIProgressViewStyle style = [TiUtils intValue:[self valueForUndefinedKey:@"style"] def:UIProgressViewStyleDefault]; diff --git a/tests/Resources/ti.ui.progressbar.test.js b/tests/Resources/ti.ui.progressbar.test.js index 493d870e761..70c9675f598 100644 --- a/tests/Resources/ti.ui.progressbar.test.js +++ b/tests/Resources/ti.ui.progressbar.test.js @@ -33,6 +33,29 @@ describe('Titanium.UI.ProgressBar', () => { }); }); + describe('.animated', () => { + it('is a Boolean', () => { + const bar = Ti.UI.createProgressBar(); + should(bar).have.property('animated').which.is.a.Boolean(); + }); + + it('defaults to true', () => { + const bar = Ti.UI.createProgressBar(); + should(bar.animated).be.true(); + }); + + it('can be initialized false', () => { + const bar = Ti.UI.createProgressBar({ animated: false }); + should(bar.animated).be.false(); + }); + + it('can be set false', () => { + const bar = Ti.UI.createProgressBar(); + bar.animated = false; + should(bar.animated).be.false(); + }); + }); + describe('.color', () => { beforeEach(() => { bar = Ti.UI.createProgressBar({ color: 'red' });