Skip to content

Commit

Permalink
feat: add animation support to Ti.UI.ProgressBar
Browse files Browse the repository at this point in the history
Fixes TIMOB-28367
  • Loading branch information
jquick-axway authored and ewanharris committed Jun 10, 2021
1 parent fdfd7c5 commit 387d6be
Show file tree
Hide file tree
Showing 7 changed files with 48 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

@Kroll.proxy(creatableInModule = UIModule.class,
propertyAccessors = {
TiC.PROPERTY_ANIMATED,
TiC.PROPERTY_MIN,
TiC.PROPERTY_MAX,
TiC.PROPERTY_VALUE,
Expand All @@ -29,6 +30,7 @@ public class ProgressBarProxy extends TiViewProxy
public ProgressBarProxy()
{
super();
defaultValues.put(TiC.PROPERTY_ANIMATED, true);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down Expand Up @@ -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)
Expand Down
6 changes: 6 additions & 0 deletions apidoc/Titanium/UI/ProgressBar.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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: |
Expand Down
2 changes: 1 addition & 1 deletion iphone/Classes/TiUIProgressBar.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
UIProgressViewStyle style;
CGFloat max;
CGFloat min;

BOOL animated;
UILabel *messageLabel;

#ifdef TI_USE_AUTOLAYOUT
Expand Down
8 changes: 7 additions & 1 deletion iphone/Classes/TiUIProgressBar.m
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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];
Expand All @@ -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
Expand Down
6 changes: 6 additions & 0 deletions iphone/Classes/TiUIProgressBarProxy.m
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand Down
23 changes: 23 additions & 0 deletions tests/Resources/ti.ui.progressbar.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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' });
Expand Down

0 comments on commit 387d6be

Please sign in to comment.