Skip to content

Commit

Permalink
Update date picker background dynamically for Dark Theme in iOS
Browse files Browse the repository at this point in the history
  • Loading branch information
Anjana Rajeev committed Jun 25, 2020
1 parent bd87605 commit 5bacffd
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions 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

0 comments on commit 5bacffd

Please sign in to comment.