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

Added IOS UIBlurEffectStyles (theme's) & added option to hide title and/or blur #40

Merged
merged 2 commits into from
Oct 19, 2018
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
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -117,8 +117,8 @@ options conform to the following interface:

```ts
export interface PickerOptions {
title?: string; // iOS ONLY: The title to display above the picker, defaults to "Choose A Time" or "Choose A Date"
theme?: string; // iOS ONLY: light for a light blurry effect, dark for a dark blurry effect - defaults to dark
title?: string; // iOS ONLY: The title to display above the picker, default hidden.
theme?: string; // iOS ONLY: avalible options: none, extralight, light, regular, dark, extradark and prominent.
maxDate?: Date;
minDate?: Date;
startingHour?: number; // Ignored on pickDate()
Expand Down
8 changes: 5 additions & 3 deletions demo/app/main-view-model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ export class HelloWorldModel extends Observable {
theme: "light",
startingDate: new Date('2018-11-17'),
maxDate: new Date(),

minDate: new Date('2018-09-19')
}).then((result:any) => {
if (result) {
Expand All @@ -37,6 +38,7 @@ export class HelloWorldModel extends Observable {
startingDate: new Date('2018-11-17'),
datePickerMode: "spinner"
}).then((result:any) => {

if (result) {
this.set("date", "Date is: " + result.day + "-" + result.month + "-" + result.year);
} else {
Expand All @@ -46,7 +48,7 @@ export class HelloWorldModel extends Observable {
.catch((error) => {
console.log("Error: " + error);
});
};
}

selectTime() {
this.modalDatetimepicker.pickTime(<PickerOptions>{
Expand All @@ -59,7 +61,7 @@ export class HelloWorldModel extends Observable {
hour: 15,
minute: 30
}
}).then((result:any) => {
}).then((result: any) => {
if (result) {
this.set("time", "Time is: " + result.hour + ":" + result.minute);
} else {
Expand All @@ -69,5 +71,5 @@ export class HelloWorldModel extends Observable {
.catch((error) => {
console.log("Error: " + error);
});
};
}
}
108 changes: 68 additions & 40 deletions src/modal-datetimepicker.ios.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,13 +61,6 @@ export class ModalDatetimepicker {
myResolve = resolve;
if (!options.type) options.type = "date";
if (!options.theme) options.theme = "dark";
if (!options.title) {
if (options.type === "date") {
options.title = "Choose A Date";
} else {
options.title = "Choose A Time";
}
}

let startingDate = new Date();
if (options.type === "date") {
Expand All @@ -83,7 +76,10 @@ export class ModalDatetimepicker {
if (options.startingHour !== undefined && options.startingHour >= 0) {
startingDate.setHours(options.startingHour);
}
if (options.startingMinute !== undefined && options.startingMinute >= 0) {
if (
options.startingMinute !== undefined &&
options.startingMinute >= 0
) {
startingDate.setMinutes(options.startingMinute);
}
}
Expand All @@ -109,11 +105,37 @@ export class ModalDatetimepicker {
window.addSubview(effectView);
window.bringSubviewToFront(effectView);
UIView.animateWithDurationAnimations(0.4, () => {
effectView.effect = UIBlurEffect.effectWithStyle(
options.theme === "light"
? UIBlurEffectStyle.Light
: UIBlurEffectStyle.Dark
);
let theme = UIBlurEffectStyle.Light;
switch (options.theme) {
case "extralight":
theme = UIBlurEffectStyle.ExtraLight;
break;
case "light":
theme = UIBlurEffectStyle.Light;
break;
case "regular":
theme = UIBlurEffectStyle.Regular;
break;
case "dark":
theme = UIBlurEffectStyle.Dark;
break;
case "extradark":
theme = UIBlurEffectStyle.ExtraDark;
break;
case "prominent":
theme = UIBlurEffectStyle.Prominent;
break;
default:
theme = UIBlurEffectStyle.Light;
break;
}

// dont display if theme is none
if (options.theme !== "none") {
effectView.effect = UIBlurEffect.effectWithStyle(theme);
} else {
effectView.effect = null;
}
});

bottomContentContainer = UIView.alloc().init();
Expand Down Expand Up @@ -237,32 +259,34 @@ export class ModalDatetimepicker {
bottomContentContainer.addSubview(pickerHolderView);
bottomContentContainer.bringSubviewToFront(pickerHolderView);

titleLabel = this.labelFactory(
options.title,
UIColor.whiteColor,
true,
25
);
titleLabel.textAlignment = NSTextAlignment.Center;
titleLabel.frame = CGRectMake(
0,
20,
containerBounds.size.width,
containerBounds.size.height - 360
);

titleLabel.transform = CGAffineTransformMakeScale(0.8, 0.8);
titleLabel.adjustsFontForContentSizeCategory = true;
titleLabel.adjustsFontSizeToFitWidth = true;
titleLabel.layer.masksToBounds = false;
titleLabel.alpha = 0;
titleLabel.autoresizingMask =
UIViewAutoresizing.FlexibleHeight |
UIViewAutoresizing.FlexibleTopMargin |
UIViewAutoresizing.FlexibleWidth;
// Only if title is set
if (options.title) {
titleLabel = this.labelFactory(
options.title,
UIColor.whiteColor,
true,
25
);
titleLabel.textAlignment = NSTextAlignment.Center;
titleLabel.frame = CGRectMake(
0,
20,
containerBounds.size.width,
containerBounds.size.height - 360
);

window.addSubview(titleLabel);
window.bringSubviewToFront(titleLabel);
titleLabel.transform = CGAffineTransformMakeScale(0.8, 0.8);
titleLabel.adjustsFontForContentSizeCategory = true;
titleLabel.adjustsFontSizeToFitWidth = true;
titleLabel.layer.masksToBounds = false;
titleLabel.alpha = 0;
titleLabel.autoresizingMask =
UIViewAutoresizing.FlexibleHeight |
UIViewAutoresizing.FlexibleTopMargin |
UIViewAutoresizing.FlexibleWidth;
window.addSubview(titleLabel);
window.bringSubviewToFront(titleLabel);
}

window.addSubview(bottomContentContainer);
window.bringSubviewToFront(bottomContentContainer);
Expand All @@ -276,8 +300,12 @@ export class ModalDatetimepicker {
0,
0
);
titleLabel.transform = CGAffineTransformMakeScale(1, 1);
titleLabel.alpha = 1;

// Only if title is set
if (options.title) {
titleLabel.transform = CGAffineTransformMakeScale(1, 1);
titleLabel.alpha = 1;
}
},
() => {
// console.dir("animation completed");
Expand Down