Skip to content

Commit

Permalink
Merge pull request #6 from ketuvin/master
Browse files Browse the repository at this point in the history
Add indicatorFillColor and indicatorColor properties back
  • Loading branch information
farfromrefug authored Sep 27, 2021
2 parents 0ebf647 + f3a7dad commit 880984d
Show file tree
Hide file tree
Showing 3 changed files with 125 additions and 3 deletions.
52 changes: 51 additions & 1 deletion src/pulltorefresh-common.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ContentView, CSSType, Property, View } from '@nativescript/core';
import { Color, ContentView, CssProperty, CSSType, Property, Style, View } from '@nativescript/core';
import { PullToRefresh as PullToRefreshDefinition } from '.';

@CSSType('PullToRefresh')
Expand Down Expand Up @@ -29,3 +29,53 @@ export const refreshingProperty = new Property<PullToRefreshBase, boolean>({
defaultValue: false,
});
refreshingProperty.register(PullToRefreshBase);

export const indicatorColorProperty = new Property<PullToRefreshBase, Color>({
name: 'indicatorColor',
affectsLayout: true,
valueConverter: (v) => {
if (!Color.isValid(v)) {
return null;
}
return new Color(v);
},
});
indicatorColorProperty.register(PullToRefreshBase);

export const indicatorColorStyleProperty = new CssProperty<Style, Color>({
name: 'indicatorColorStyle',
cssName: 'indicator-color',
affectsLayout: true,
valueConverter: (v) => {
if (!Color.isValid(v)) {
return null;
}
return new Color(v);
},
});
indicatorColorStyleProperty.register(Style);

export const indicatorFillColorProperty = new Property<PullToRefreshBase, Color>({
name: 'indicatorFillColor',
affectsLayout: true,
valueConverter: (v) => {
if (!Color.isValid(v)) {
return null;
}
return new Color(v);
},
});
indicatorFillColorProperty.register(PullToRefreshBase);

export const indicatorFillColorStyleProperty = new CssProperty<Style, Color>({
name: 'indicatorFillColorStyle',
cssName: 'indicator-fill-color',
affectsLayout: true,
valueConverter: (v) => {
if (!Color.isValid(v)) {
return null;
}
return new Color(v);
},
});
indicatorFillColorStyleProperty.register(Style);
30 changes: 29 additions & 1 deletion src/pulltorefresh.android.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { backgroundColorProperty, colorProperty } from '@nativescript/core';
import { Color } from '@nativescript/core/color';
import { PullToRefreshBase, refreshingProperty } from './pulltorefresh-common';
import { indicatorColorProperty, indicatorColorStyleProperty, indicatorFillColorProperty, indicatorFillColorStyleProperty, PullToRefreshBase, refreshingProperty } from './pulltorefresh-common';

export * from './pulltorefresh-common';

Expand Down Expand Up @@ -62,4 +62,32 @@ export class PullToRefresh extends PullToRefreshBase {
const color = value instanceof Color ? value.android : value;
this.nativeView.setProgressBackgroundColorSchemeColor(color);
}

[indicatorColorProperty.setNative](value: any) {
const color = value ? value.android : this.color;
this.nativeView.setColorSchemeColors([color]);
}

[indicatorColorStyleProperty.setNative](value: any) {
// Inline property has priority
if ((this as any).indicatorColor) {
return;
}
const color = value ? value.android : this.color;
this.nativeView.setColorSchemeColors([color]);
}

[indicatorFillColorProperty.setNative](value: any) {
const color = value ? value.android : this.backgroundColor;
this.nativeView.setProgressBackgroundColorSchemeColor(color);
}

[indicatorFillColorStyleProperty.setNative](value: any) {
// Inline property has priority
if ((this as any).indicatorFillColor) {
return;
}
const color = value ? value.android : this.backgroundColor;
this.nativeView.setProgressBackgroundColorSchemeColor(color);
}
}
46 changes: 45 additions & 1 deletion src/pulltorefresh.ios.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import {
colorProperty,
Utils,
} from '@nativescript/core';
import { PullToRefreshBase, refreshingProperty } from './pulltorefresh-common';
import { indicatorColorProperty, indicatorColorStyleProperty, indicatorFillColorProperty, indicatorFillColorStyleProperty, PullToRefreshBase, refreshingProperty } from './pulltorefresh-common';

export * from './pulltorefresh-common';

Expand Down Expand Up @@ -137,4 +137,48 @@ export class PullToRefresh extends PullToRefreshBase {

this.refreshControl.backgroundColor = color;
}

[indicatorColorProperty.getDefault](): UIColor {
return this.refreshControl.tintColor;
}

[indicatorColorProperty.setNative](value: any) {
const color = value ? value.ios : this.color;
this.refreshControl.tintColor = color;
}

[indicatorColorStyleProperty.getDefault](): UIColor {
return this.refreshControl.tintColor;
}

[indicatorColorStyleProperty.setNative](value: any) {
// Inline property has priority
if ((this as any).indicatorColor) {
return;
}
const color = value ? value.ios : this.color;
this.refreshControl.tintColor = color;
}

[indicatorFillColorProperty.getDefault](): UIColor {
return this.refreshControl.backgroundColor;
}

[indicatorFillColorProperty.setNative](value: any) {
const color = value ? value.ios : this.backgroundColor;
this.refreshControl.backgroundColor = color;
}

[indicatorFillColorStyleProperty.getDefault](): UIColor {
return this.refreshControl.backgroundColor;
}

[indicatorFillColorStyleProperty.setNative](value: any) {
// Inline property has priority
if ((this as any).indicatorFillColor) {
return;
}
const color = value ? value.ios : this.backgroundColor;
this.refreshControl.backgroundColor = color;
}
}

0 comments on commit 880984d

Please sign in to comment.