Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add indicatorFillColor and indicatorColor properties back #6

Merged
merged 1 commit into from
Sep 27, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;
}
}