Skip to content

Commit

Permalink
merging #46
Browse files Browse the repository at this point in the history
  • Loading branch information
shiv19 committed Apr 3, 2019
2 parents c637768 + baab8fc commit 093bbe1
Show file tree
Hide file tree
Showing 6 changed files with 123 additions and 63 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,8 @@ options conform to the following interface:
```ts
export interface PickerOptions {
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.
theme?: string; // iOS ONLY: avalible options: none, extralight, light, regular, dark, extradark, prominent and overlay.
overlayAlpha?: number; // iOS ONLY: when theme is 'overlay', available options: 0.0 to 1.0
maxDate?: Date;
minDate?: Date;
startingHour?: number; // Ignored on pickDate()
Expand Down
5 changes: 3 additions & 2 deletions demo/app/main-page.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,11 @@
<Button text="Pick a Date" tap="{{ selectDate }}" style="margin-top: 100;" class="btn btn-primary btn-active"/>
<Button text="Pick a Date (spinner mode)" tap="{{ selectDateSpinner }}" style="margin-top: 20;" class="btn btn-primary btn-active"/>
<Button text="Pick a Time" tap="{{ selectTime }}" style="margin-top: 20; margin-bottom: 100;" class="btn btn-primary btn-active"/>
<Button text="Pick a Time (Overlay)" tap="{{ selectDateOverlay }}" style="margin-top: 20; margin-bottom: 100;" class="btn btn-primary btn-active"/>
<Button text="Close programatically" tap="{{ closeProgramatically }}" style="margin-top: 20; margin-bottom: 100;" class="btn btn-primary btn-active"/>
<Label visibility="{{ date ? 'visible' : 'collapsed' }}" text="{{date}}" style="color: white; text-align: center; font-size: 20; font-weight: bold;" />
<Label visibility="{{ time ? 'visible' : 'collapsed' }}" text="{{time}}" style="color: white; text-align: center; font-size: 20; font-weight: bold;" />
</StackLayout>
</StackLayout>

</GridLayout>
</Page>
</Page>
22 changes: 19 additions & 3 deletions demo/app/main-view-model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ 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 @@ -41,7 +40,6 @@ 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 @@ -53,7 +51,7 @@ export class HelloWorldModel extends Observable {
.catch((error) => {
console.log("Error: " + error);
});
};
}

selectDateSpinner() {
this.modalDatetimepicker.pickDate(<PickerOptions>{
Expand All @@ -62,7 +60,25 @@ 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 {
this.set("date", false);
}
})
.catch((error) => {
console.log("Error: " + error);
});
}

selectDateOverlay() {
this.modalDatetimepicker.pickDate(<PickerOptions>{
title: "Configurable Title",
theme: "overlay",
startingDate: new Date('2018-11-17'),
maxDate: new Date(),
minDate: new Date('2018-09-19')
}).then((result:any) => {
if (result) {
this.set("date", "Date is: " + result.day + "-" + result.month + "-" + result.year);
} else {
Expand Down
1 change: 1 addition & 0 deletions src/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ export interface PickerOptions {
type?: string;
title?: string;
theme?: string;
overlayAlpha?: number;
maxDate?: Date;
minDate?: Date;
startingDate?: Date;
Expand Down
148 changes: 92 additions & 56 deletions src/modal-datetimepicker.ios.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ const buttonHandler = ButtonHandler.new();

let myResolve;
let window: UIWindow;
let effectView: UIVisualEffectView; // this view blurs the background
let effectView: UIVisualEffectView; // this view potentially blurs the background
let overlayView: UIView; // this view potentially overlays the background
let pickerHolderView: UIView; // this is the view that holds the picker
let bottomContentContainer: UIView; // this view holds the picker and the action buttons.
// let topContentContainer: UIView; // this is the view the holds the title.
Expand All @@ -62,6 +63,7 @@ export class ModalDatetimepicker {
myResolve = resolve;
if (!options.type) options.type = "date";
if (!options.theme) options.theme = "dark";
if (!options.overlayAlpha) options.overlayAlpha = 0.7;

let startingDate = new Date();
if (options.type === "date") {
Expand Down Expand Up @@ -93,51 +95,71 @@ export class ModalDatetimepicker {
window = UIApplication.sharedApplication.keyWindow;
const containerBounds = window.bounds;

// blur the background of the application.
effectView = UIVisualEffectView.alloc().init();
effectView.frame = CGRectMake(
containerBounds.origin.x,
containerBounds.origin.y,
containerBounds.size.width,
containerBounds.size.height + 20
);
effectView.autoresizingMask =
UIViewAutoresizing.FlexibleWidth | UIViewAutoresizing.FlexibleHeight;
window.addSubview(effectView);
window.bringSubviewToFront(effectView);
UIView.animateWithDurationAnimations(0.4, () => {
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;
}
if (options.theme === "overlay") {
// overlay the background of the application.
overlayView = UIView.alloc().init();
overlayView.frame = CGRectMake(
containerBounds.origin.x,
containerBounds.origin.y,
containerBounds.size.width,
containerBounds.size.height + 20
);
overlayView.autoresizingMask =
UIViewAutoresizing.FlexibleWidth | UIViewAutoresizing.FlexibleHeight;
window.addSubview(overlayView);
window.bringSubviewToFront(overlayView);

// dont display if theme is none
if (options.theme !== "none") {
effectView.effect = UIBlurEffect.effectWithStyle(theme);
} else {
effectView.effect = null;
}
});
UIView.animateWithDurationAnimations(0.4, () => {
overlayView.backgroundColor = UIColor.blackColor.colorWithAlphaComponent(
options.overlayAlpha
);
});
} else {
// blur the background of the application.
effectView = UIVisualEffectView.alloc().init();
effectView.frame = CGRectMake(
containerBounds.origin.x,
containerBounds.origin.y,
containerBounds.size.width,
containerBounds.size.height + 20
);
effectView.autoresizingMask =
UIViewAutoresizing.FlexibleWidth | UIViewAutoresizing.FlexibleHeight;
window.addSubview(effectView);
window.bringSubviewToFront(effectView);
UIView.animateWithDurationAnimations(0.4, () => {
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:
break;
}

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

bottomContentContainer = UIView.alloc().init();
bottomContentContainer.frame = CGRectMake(
Expand Down Expand Up @@ -200,7 +222,8 @@ export class ModalDatetimepicker {
40
);
cancelButton.setTitleColorForState(
(options.cancelLabelColor && options.cancelLabelColor.ios) || UIColor.whiteColor,
(options.cancelLabelColor && options.cancelLabelColor.ios) ||
UIColor.whiteColor,
UIControlState.Normal
);
cancelButton.titleLabel.font = UIFont.systemFontOfSize(18);
Expand Down Expand Up @@ -234,7 +257,8 @@ export class ModalDatetimepicker {
40
);
doneButton.setTitleColorForState(
(options.doneLabelColor && options.doneLabelColor.ios) || UIColor.colorWithRedGreenBlueAlpha(0, 0.6, 1, 1),
(options.doneLabelColor && options.doneLabelColor.ios) ||
UIColor.colorWithRedGreenBlueAlpha(0, 0.6, 1, 1),
UIControlState.Normal
);
doneButton.titleLabel.font = UIFont.boldSystemFontOfSize(18);
Expand Down Expand Up @@ -291,7 +315,6 @@ export class ModalDatetimepicker {

window.addSubview(bottomContentContainer);
window.bringSubviewToFront(bottomContentContainer);
// let animationOptions: UIViewAnimationOptions;
UIView.animateWithDurationDelayOptionsAnimationsCompletion(
0.4,
0,
Expand All @@ -308,16 +331,18 @@ export class ModalDatetimepicker {
titleLabel.alpha = 1;
}
},
() => {
// console.dir("animation completed");
}
() => {}
);
});
}

private labelFactory(text, color, shadow, size) {
private labelFactory(
text: string,
color: UIColor,
shadow: boolean,
size: number
) {
window = UIApplication.sharedApplication.keyWindow;
const containerBounds = window.bounds;
const label = UILabel.alloc().init();
label.text = text;
label.font = UIFont.boldSystemFontOfSize(size);
Expand Down Expand Up @@ -352,12 +377,17 @@ export class ModalDatetimepicker {
this.close(response);
}

public close(response?) {
public close(response?: any) {
if (!response) response = false;
UIView.animateWithDurationAnimationsCompletion(
0.3,
() => {
effectView.effect = null;
if (effectView) {
effectView.effect = null;
}
if (overlayView) {
overlayView.backgroundColor = UIColor.clearColor;
}
bottomContentContainer.transform = CGAffineTransformMakeTranslation(
0,
320
Expand All @@ -368,7 +398,12 @@ export class ModalDatetimepicker {
}
},
() => {
effectView.removeFromSuperview();
if (effectView) {
effectView.removeFromSuperview();
}
if (overlayView) {
overlayView.removeFromSuperview();
}
bottomContentContainer.removeFromSuperview();
if (titleLabel) {
titleLabel.removeFromSuperview();
Expand All @@ -385,6 +420,7 @@ export interface PickerOptions {
type?: string;
title?: string;
theme?: string;
overlayAlpha?: number;
maxDate?: Date;
minDate?: Date;
startingDate?: Date;
Expand Down
7 changes: 6 additions & 1 deletion src/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "nativescript-modal-datetimepicker",
"version": "1.1.12",
"version": "1.1.13",
"description": "A nice looking modal date time picker.",
"main": "modal-datetimepicker",
"typings": "index.d.ts",
Expand Down Expand Up @@ -75,6 +75,11 @@
"name": "Brad Martin",
"email": "[email protected]",
"url": "https://github.com/bradmartin"
},
{
"name": "Luke Curran",
"email": "[email protected]",
"url": "https://github.com/MCurran16"
}
],
"repository": {
Expand Down

0 comments on commit 093bbe1

Please sign in to comment.