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

Update date picker background dynamically for Dark Theme in iOS #285

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
25 changes: 24 additions & 1 deletion src/ios/DatePicker.m
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,13 @@ - (void)show:(CDVInvokedUrlCommand*)command {
}

- (BOOL)showForPhone:(NSMutableDictionary *)options {
BOOL addListenerForTraitChange;
if(!self.datePickerContainer){
[[NSBundle mainBundle] loadNibNamed:@"DatePicker" owner:self options:nil];
addListenerForTraitChange = YES;
} else {
self.datePickerContainer.backgroundColor = [[UIColor blackColor] colorWithAlphaComponent:0.4];
addListenerForTraitChange = NO;
}

[self updateDatePicker:options];
Expand Down Expand Up @@ -91,14 +94,34 @@ - (BOOL)showForPhone:(NSMutableDictionary *)options {
animations:^{
self.datePickerComponentsContainer.frame = frame;
self.datePickerContainer.backgroundColor = [[UIColor blackColor] colorWithAlphaComponent:0.4];
[self adjustDatePickerContainerBg];

} completion:^(BOOL finished) {


if (addListenerForTraitChange) {
// Without the check, it would add the observer for every single show command
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(applicationEnteredForeground:)
name:UIApplicationDidBecomeActiveNotification
object:nil];
}
}];

return true;
}

- (void)applicationEnteredForeground:(NSNotification *)notification {
[self adjustDatePickerContainerBg];
}

-(void) adjustDatePickerContainerBg {
if (self.viewController.traitCollection.userInterfaceStyle == UIUserInterfaceStyleDark) {
self.datePickerComponentsContainer.subviews[0].backgroundColor = [[UIColor darkGrayColor] colorWithAlphaComponent:1];
} else {
self.datePickerComponentsContainer.subviews[0].backgroundColor = [[UIColor whiteColor] colorWithAlphaComponent:1];
}
}

- (BOOL)showForPad:(NSMutableDictionary *)options {
self.datePickerPopover = [self createPopover:options];
return true;
Expand Down