Skip to content

Commit

Permalink
Merge branch 'master' into TIMOB-27328
Browse files Browse the repository at this point in the history
  • Loading branch information
ssjsamir committed Aug 19, 2019
2 parents f11028f + d3f757a commit 7a493ef
Show file tree
Hide file tree
Showing 12 changed files with 165 additions and 9 deletions.
39 changes: 39 additions & 0 deletions apidoc/Titanium/App/iOS/iOS.yml
Original file line number Diff line number Diff line change
Expand Up @@ -486,6 +486,30 @@ properties:
osver: {ios: {min: "11.0"}}
since: "7.3.0"

- name: USER_INTERFACE_STYLE_UNSPECIFIED
summary: An unspecified interface style.
description: Used in the `userInterfaceStyle` property.
type: Number
permission: read-only
osver: {ios: {min: "13.0"}}
since: "8.2.0"

- name: USER_INTERFACE_STYLE_LIGHT
summary: A light interface style.
description: Used in the `userInterfaceStyle` property.
type: Number
permission: read-only
osver: {ios: {min: "13.0"}}
since: "8.2.0"

- name: USER_INTERFACE_STYLE_DARK
summary: A dark interface style.
description: Used in the `userInterfaceStyle` property.
type: Number
permission: read-only
osver: {ios: {min: "13.0"}}
since: "8.2.0"

- name: UTTYPE_TEXT
summary: |
Uniform type identifier for all text types.
Expand Down Expand Up @@ -800,6 +824,16 @@ properties:
osver: {ios: {min: "8.0"}}
since: "3.4.0"

- name: userInterfaceStyle
summary: The style associated with the user interface.
description: |
Use this property to determine whether your interface should be configured with a dark or light appearance.
The default value of this trait is set to the corresponding appearance setting on the user's device.
type: Array<String>
permission: read-only
osver: {ios: {min: "13.0"}}
since: "8.2.0"

events:
- name: notification
summary: Fired when a local notification is received by the application.
Expand Down Expand Up @@ -1360,6 +1394,11 @@ events:
osver: {ios: {min: "8.0"}}
since: "6.0.0"

- name: traitcollectionchange
summary: Fired when the trait collection of the device changes, e.g. the user interface style.
platforms: [iphone, ipad]
since: "8.2.0"

---
name: NotificationParams
summary: |
Expand Down
51 changes: 51 additions & 0 deletions iphone/Classes/TiAppiOSProxy.m
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,13 @@ - (void)_listenerAdded:(NSString *)type count:(int)count
name:kTiApplicationLaunchedFromURL
object:nil];
}

if ((count == 1) && [type isEqual:@"traitcollectionchange"]) {
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(didChangeTraitCollection:)
name:kTiTraitCollectionChanged
object:nil];
}
}

- (void)_listenerRemoved:(NSString *)type count:(int)count
Expand Down Expand Up @@ -179,10 +186,25 @@ - (void)_listenerRemoved:(NSString *)type count:(int)count
if ((count == 1) && [type isEqual:@"shortcutitemclick"]) {
[[NSNotificationCenter defaultCenter] removeObserver:self name:kTiApplicationShortcut object:nil];
}
if ((count == 1) && [type isEqual:@"traitcollectionchange"]) {
[[NSNotificationCenter defaultCenter] removeObserver:self name:kTiTraitCollectionChanged object:nil];
}
}

#pragma mark Public

#if __IPHONE_OS_VERSION_MAX_ALLOWED >= 130000
- (NSNumber *)userInterfaceStyle
{
return @(TiApp.controller.traitCollection.userInterfaceStyle);
}
#endif

- (void)didChangeTraitCollection:(NSNotification *)info
{
[self fireEvent:@"traitcollectionchange"];
}

- (void)didReceiveApplicationShortcutNotification:(NSNotification *)info
{
NSMutableDictionary *event = [[NSMutableDictionary alloc] initWithDictionary:@{
Expand Down Expand Up @@ -1267,6 +1289,35 @@ - (NSNumber *)USER_NOTIFICATION_CATEGORY_OPTION_HIDDEN_PREVIEWS_SHOW_SUBTITLE
return NUMINT(0);
}

#if __IPHONE_OS_VERSION_MAX_ALLOWED >= 130000
- (NSNumber *)USER_INTERFACE_STYLE_UNSPECIFIED
{
if ([TiUtils isIOSVersionOrGreater:@"13.0"]) {
return NUMINT(UIUserInterfaceStyleUnspecified);
}

return NUMINT(0);
}

- (NSNumber *)USER_INTERFACE_STYLE_LIGHT
{
if ([TiUtils isIOSVersionOrGreater:@"13.0"]) {
return NUMINT(UIUserInterfaceStyleLight);
}

return NUMINT(0);
}

- (NSNumber *)USER_INTERFACE_STYLE_DARK
{
if ([TiUtils isIOSVersionOrGreater:@"13.0"]) {
return NUMINT(UIUserInterfaceStyleDark);
}

return NUMINT(0);
}
#endif

#pragma mark UTI Text Type Constants

- (CFStringRef)UTTYPE_TEXT
Expand Down
6 changes: 5 additions & 1 deletion iphone/Classes/TiUIActivityIndicator.m
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,11 @@ - (void)setColor_:(id)value
textColor = [newColor retain];
if (messageLabel != nil) {
if (textColor == nil) {
[messageLabel setTextColor:[UIColor blackColor]];
#if __IPHONE_OS_VERSION_MAX_ALLOWED >= 130000
[messageLabel setTextColor:[TiUtils isIOSVersionOrGreater:@"13.0"] ? UIColor.labelColor : UIColor.blackColor];
#else
[messageLabel setTextColor:UIColor.blackColor];
#endif
} else {
[messageLabel setTextColor:textColor];
}
Expand Down
4 changes: 4 additions & 0 deletions iphone/Classes/TiUIListItem.m
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,10 @@ - (void)setPosition:(int)position isGrouped:(BOOL)grouped

- (void)applyBackgroundWithSelectedColor:(id)selectedBackgroundColor selectedImage:(id)selectedBackgroundImage
{
if (!selectedBackgroundColor && !selectedBackgroundImage) {
return; // Ignore custom selection styles for native selections
}

UIColor *sbgColor = (selectedBackgroundColor != nil) ? ([[TiUtils colorValue:selectedBackgroundColor] _color]) : nil;
UIImage *sbgImage = [[ImageLoader sharedLoader] loadImmediateStretchableImage:[TiUtils toURL:selectedBackgroundImage proxy:_proxy] withLeftCap:TiDimensionAuto topCap:TiDimensionAuto];
if (sbgImage != nil) {
Expand Down
6 changes: 5 additions & 1 deletion iphone/Classes/TiUIPicker.m
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,11 @@ - (UIControl *)picker
[(UIDatePicker *)picker setDatePickerMode:type];
[picker addTarget:self action:@selector(valueChanged:) forControlEvents:UIControlEventValueChanged];
}
[picker setBackgroundColor:[UIColor whiteColor]];
#if __IPHONE_OS_VERSION_MAX_ALLOWED >= 130000
[picker setBackgroundColor:[TiUtils isIOSVersionOrGreater:@"13.0"] ? UIColor.systemBackgroundColor : UIColor.whiteColor];
#else
[picker setBackgroundColor:UIColor.whiteColor];
#endif
[self addSubview:picker];
}
return picker;
Expand Down
17 changes: 15 additions & 2 deletions iphone/Classes/TiUITableViewRowProxy.m
Original file line number Diff line number Diff line change
Expand Up @@ -384,6 +384,10 @@ - (void)configureRightSide:(UITableViewCell *)cell

- (void)configureBackground:(UITableViewCell *)cell
{
if (![self shouldUseBackgroundView]) {
return; // Ignore custom selection styles for native selections
}

[(TiUITableViewCell *)cell setBackgroundGradient_:[self valueForKey:@"backgroundGradient"]];
[(TiUITableViewCell *)cell setSelectedBackgroundGradient_:[self valueForKey:@"selectedBackgroundGradient"]];

Expand Down Expand Up @@ -416,15 +420,15 @@ - (void)configureBackground:(UITableViewCell *)cell
((UIImageView *)cell.selectedBackgroundView).image = image;
}

UIColor *theColor = [Webcolor webColorNamed:selBgColor];
UIColor *theColor = [TiUtils colorValue:selBgColor].color;
cell.selectedBackgroundView.backgroundColor = ((theColor == nil) ? [UIColor clearColor] : theColor);
} else {
if (![cell.selectedBackgroundView isKindOfClass:[TiSelectedCellBackgroundView class]]) {
cell.selectedBackgroundView = [[[TiSelectedCellBackgroundView alloc] initWithFrame:CGRectZero] autorelease];
}
TiSelectedCellBackgroundView *selectedBGView = (TiSelectedCellBackgroundView *)cell.selectedBackgroundView;
selectedBGView.grouped = [[table tableView] style] == UITableViewStyleGrouped;
UIColor *theColor = [Webcolor webColorNamed:selBgColor];
UIColor *theColor = [TiUtils colorValue:selBgColor].color;
if (theColor == nil) {
switch (cell.selectionStyle) {
case UITableViewCellSelectionStyleGray:
Expand Down Expand Up @@ -842,6 +846,15 @@ - (void)fireEvent:(NSString *)type withObject:(id)obj propagate:(BOOL)propagate
[super fireEvent:type withObject:obj propagate:propagate reportSuccess:report errorCode:code message:message];
}

- (BOOL)shouldUseBackgroundView
{
return [self valueForKey:@"selectedBackgroundColor"]
|| [self valueForKey:@"backgroundImage"]
|| [self valueForKey:@"selectedBackgroundImage"]
|| [self valueForKey:@"backgroundLeftCap"]
|| [self valueForKey:@"backgroundTopCap"];
}

- (void)setSelectedBackgroundColor:(id)arg
{
[self replaceValue:arg forKey:@"selectedBackgroundColor" notification:NO];
Expand Down
1 change: 0 additions & 1 deletion iphone/TitaniumKit/TitaniumKit/Sources/API/TiApp.m
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,6 @@ - (UIView *)splashScreenView
splashScreenView = [[launchScreenViewController view] retain];
} else {
splashScreenView = [[UIImageView alloc] init];
[splashScreenView setBackgroundColor:[UIColor yellowColor]];
[splashScreenView setAutoresizingMask:UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth];
[splashScreenView setContentMode:UIViewContentModeScaleToFill];

Expand Down
1 change: 1 addition & 0 deletions iphone/TitaniumKit/TitaniumKit/Sources/API/TiBase.h
Original file line number Diff line number Diff line change
Expand Up @@ -603,6 +603,7 @@ extern NSString *const kTiWatchKitExtensionRequest;
extern NSString *const kTiContinueActivity;
extern NSString *const kTiApplicationShortcut;
extern NSString *const kTiApplicationLaunchedFromURL;
extern NSString *const kTiTraitCollectionChanged;

#ifndef TI_USE_AUTOLAYOUT
extern NSString *const kTiBehaviorSize;
Expand Down
1 change: 1 addition & 0 deletions iphone/TitaniumKit/TitaniumKit/Sources/API/TiBase.m
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ void TiLogMessage(NSString *str, ...)
NSString *const kTiContinueActivity = @"TiContinueActivity";
NSString *const kTiApplicationShortcut = @"TiApplicationShortcut";
NSString *const kTiApplicationLaunchedFromURL = @"TiApplicationLaunchedFromURL";
NSString *const kTiTraitCollectionChanged = @"TiTraitCollectionChanged";

#ifndef TI_USE_AUTOLAYOUT
NSString *const kTiBehaviorSize = @"SIZE";
Expand Down
13 changes: 9 additions & 4 deletions iphone/TitaniumKit/TitaniumKit/Sources/API/TiErrorController.m
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/**
* Appcelerator Titanium Mobile
* Copyright (c) 2009-2018 by Appcelerator, Inc. All Rights Reserved.
* Copyright (c) 2009-2019 by Appcelerator, Inc. All Rights Reserved.
* Licensed under the terms of the Apache Public License
* Please see the LICENSE included with this distribution for details.
*
Expand Down Expand Up @@ -50,10 +50,15 @@ - (void)loadView
[super loadView];

// configure view controller
UIColor *errorColor = [UIColor colorWithRed:0.90 green:0.22 blue:0.21 alpha:1.0];
UIColor *errorColor = UIColor.redColor;
self.navigationItem.title = NSLocalizedString(@"Application Error", nil);
self.navigationController.navigationBar.titleTextAttributes = @{ NSForegroundColorAttributeName : errorColor };
[self.view setBackgroundColor:[UIColor colorWithRed:0.96 green:0.96 blue:0.96 alpha:1.0]];

#if __IPHONE_OS_VERSION_MAX_ALLOWED >= 130000
[self.view setBackgroundColor:[TiUtils isIOSVersionOrGreater:@"13.0"] ? UIColor.systemBackgroundColor : UIColor.whiteColor];
#else
[self.view setBackgroundColor:UIColor.whiteColor];
#endif

// release previous allocations
RELEASE_TO_NIL(scrollView);
Expand Down Expand Up @@ -95,7 +100,7 @@ - (void)loadView
[messageView setScrollEnabled:NO];
[messageView setMultipleTouchEnabled:YES];
[messageView setBackgroundColor:[UIColor clearColor]];
[messageView setTextColor:[UIColor colorWithRed:0.90 green:0.22 blue:0.21 alpha:1.0]];
[messageView setTextColor:errorColor];
[messageView setText:error];
[messageView setFont:[UIFont fontWithName:@"Courier" size:15]];
[scrollView addSubview:messageView];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1415,6 +1415,9 @@ - (TiOrientationFlags)getFlags:(BOOL)checkModal
- (void)traitCollectionDidChange:(UITraitCollection *)previousTraitCollection;
{
[self resetTransformAndForceLayout:YES];

[[NSNotificationCenter defaultCenter] postNotificationName:kTiTraitCollectionChanged];

[super traitCollectionDidChange:previousTraitCollection];
}

Expand Down
32 changes: 32 additions & 0 deletions tests/Resources/ti.app.ios.addontest.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/*
* Appcelerator Titanium Mobile
* Copyright (c) 2018-Present by Appcelerator, Inc. All Rights Reserved.
* Licensed under the terms of the Apache Public License
* Please see the LICENSE included with this distribution for details.
*/
/* eslint-env mocha */
/* eslint no-unused-expressions: "off" */
'use strict';
var should = require('./utilities/assertions');

describe.ios('Titanium.App.iOS', function () {

// To be added to the existing "#constants" test case
it('#constants', function () {
should(Ti.App.iOS.USER_INTERFACE_STYLE_UNSPECIFIED).be.a.Number;
should(Ti.App.iOS.USER_INTERFACE_STYLE_LIGHT).be.a.Number;
should(Ti.App.iOS.USER_INTERFACE_STYLE_DARK).be.a.Number;
});

it('.userInterfaceStyle', function () {
var isiOS13 = (Ti.Platform.osname === 'iphone' || Ti.Platform.osname === 'ipad') && (parseInt(Ti.Platform.version.split('.')[0]) >= 13);

if (!isiOS13) {
return;
}

// We only check for the type, since the value (light, dark, unspecified)
// can vary between device configs
should(Ti.App.iOS.userInterfaceStyle).be.a.Number;
});
});

0 comments on commit 7a493ef

Please sign in to comment.