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

fix(ios)(8_2_X): sf symbol handling for application shortcut #11222

Merged
merged 5 commits into from
Sep 24, 2019
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 3 additions & 1 deletion apidoc/Titanium/UI/iOS/ApplicationShortcuts.yml
Original file line number Diff line number Diff line change
Expand Up @@ -313,6 +313,8 @@ properties:

The recommended size for image files is 35dp (@2px: 70dp, @3x: 105dp). Also check the [Apple documentation](https://developer.apple.com/documentation/uikit/uiapplicationshortcuticon)
for more information on shortcut icons.

On iOS 13 and higher, with SDK 8.2.1 or higher, you can pass in the Ti.Blob instance returned from <Ti.UI.iOS.systemImage>.

type: [Number,String,Titanium.Contacts.Person]
constants: Titanium.UI.iOS.SHORTCUT_ICON_TYPE_*
Expand All @@ -323,4 +325,4 @@ properties:
description: |
The userInfo is an object containing information about the shortcut like an ID or details about it.
type: Object
optional: true
optional: true
9 changes: 9 additions & 0 deletions iphone/Classes/TiUIApplicationShortcutsProxy.m
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

#if defined(USE_TI_UIIOSAPPLICATIONSHORTCUTS) || defined(USE_TI_UIAPPLICATIONSHORTCUTS)
#import "TiUIApplicationShortcutsProxy.h"
#import <TitaniumKit/TiBlob.h>
#import <TitaniumKit/TiUtils.h>
#ifdef USE_TI_CONTACTS
#import "TiContactsPerson.h"
Expand Down Expand Up @@ -211,6 +212,14 @@ - (UIApplicationShortcutIcon *)findIcon:(id)value
return [UIApplicationShortcutIcon iconWithTemplateImageName:[self urlInAssetCatalog:value]];
}

#ifdef IS_SDK_IOS_13
if ([value isKindOfClass:[TiBlob class]] && [TiUtils isIOSVersionOrGreater:@"13.0"]) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do you need to check the iOS version here if you have the ifdef guard as well?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes. Its needed. UIApplicationShortcutIcon's api 'iconWithSystemImageName' is not available for iOS < 13. Let's say I ran my app using sdk 8.2.1 with Xcode 11 and run on iOS 12, in that case it will give error at run time.

TiBlob *blob = (TiBlob *)value;
if (blob.type == TiBlobTypeSystemImage) {
return [UIApplicationShortcutIcon iconWithSystemImageName:blob.systemImageName];
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A wild guess here: Instead of creating new blob types and all this handling, why not just introduce a new systemIcon String proxy property and pass it directly to the iconWithSystemImageName constructor? That'd probably be around 10 lines of code in total.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@hansemannn 1. UIApplicationShortcutIcon has 4 type of icons, which are getting handled from same place in SDK. And developer have to pass proper value to 'icon' property and it gets internally handled on basis of type.
2. Only one type of icon can be set at a time. Having 2 property will create confusion.
3. Similar type of handling sf symbols will be better for developer.

}
}
#endif
NSLog(@"[ERROR] Ti.UI.ApplicationShortcuts: Invalid icon provided, defaulting to use no icon.");
return nil;
}
Expand Down
10 changes: 10 additions & 0 deletions iphone/Classes/TiUIiOSApplicationShortcutsProxy.m
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

#ifdef USE_TI_UIIOSAPPLICATIONSHORTCUTS
#import "TiUIiOSApplicationShortcutsProxy.h"
#import <TitaniumKit/TiBlob.h>
#import <TitaniumKit/TiUtils.h>
#ifdef USE_TI_CONTACTS
#import "TiContactsPerson.h"
Expand Down Expand Up @@ -211,6 +212,15 @@ - (UIApplicationShortcutIcon *)findIcon:(id)value
return [UIApplicationShortcutIcon iconWithTemplateImageName:[self urlInAssetCatalog:value]];
}

#ifdef IS_SDK_IOS_13
if ([value isKindOfClass:[TiBlob class]] && [TiUtils isIOSVersionOrGreater:@"13.0"]) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same as above...

TiBlob *blob = (TiBlob *)value;
if (blob.type == TiBlobTypeSystemImage) {
return [UIApplicationShortcutIcon iconWithSystemImageName:blob.systemImageName];
}
}
#endif

NSLog(@"[ERROR] Ti.UI.iOS.ApplicationShortcuts: Invalid icon provided, defaulting to use no icon.");
return nil;
}
Expand Down
3 changes: 1 addition & 2 deletions iphone/Classes/TiUIiOSProxy.m
Original file line number Diff line number Diff line change
Expand Up @@ -394,8 +394,7 @@ - (TiBlob *)systemImage:(id)arg
return nil;
}
ENSURE_SINGLE_ARG_OR_NIL(arg, NSString);
UIImage *image = [UIImage systemImageNamed:arg];
TiBlob *blob = [[TiBlob alloc] initWithImage:image];
TiBlob *blob = [[TiBlob alloc] initWithSystemImage:arg];
return blob;
}
#endif
Expand Down
19 changes: 18 additions & 1 deletion iphone/TitaniumKit/TitaniumKit/Sources/API/TiBlob.h
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,8 @@ JSExportAs(imageWithRoundedCorner,
typedef enum {
TiBlobTypeImage = 0,
TiBlobTypeFile = 1,
TiBlobTypeData = 2
TiBlobTypeData = 2,
TiBlobTypeSystemImage = 3
} TiBlobType;

/**
Expand All @@ -95,6 +96,7 @@ typedef enum {
UIImage *image;
NSString *path;
BOOL imageLoadAttempted;
NSString *systemImageName;
}

/**
Expand Down Expand Up @@ -125,6 +127,21 @@ typedef enum {
*/
- (id)initWithImage:(UIImage *)image;

#if __IPHONE_OS_VERSION_MAX_ALLOWED >= 130000
/**
Initialize the blob with a system image.
@param imageName The system image name
*/
- (id)initWithSystemImage:(NSString *)imageName;

/**
Returns the System Image Name .
@return The string or nil.
*/
- (NSString *)systemImageName;

#endif

/**
Initialize the blob with data.
@param data_ The raw data.
Expand Down
23 changes: 23 additions & 0 deletions iphone/TitaniumKit/TitaniumKit/Sources/API/TiBlob.m
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ - (void)dealloc
RELEASE_TO_NIL(data);
RELEASE_TO_NIL(image);
RELEASE_TO_NIL(path);
RELEASE_TO_NIL(systemImageName);
[super dealloc];
}

Expand Down Expand Up @@ -136,6 +137,28 @@ - (id)initWithImage:(UIImage *)image_
return self;
}

#if __IPHONE_OS_VERSION_MAX_ALLOWED >= 130000
- (id)initWithSystemImage:(NSString *)imageName
{
if (![TiUtils isIOSVersionOrGreater:@"13.0"]) {
return nil;
}

if (self = [super init]) {
image = [[UIImage systemImageNamed:imageName] retain];
type = TiBlobTypeSystemImage;
systemImageName = [imageName retain];
mimetype = [([UIImageAlpha hasAlpha:image] ? MIMETYPE_PNG : MIMETYPE_JPEG)copy];
}
return self;
}

- (NSString *)systemImageName
{
return systemImageName;
}
#endif

- (id)initWithData:(NSData *)data_ mimetype:(NSString *)mimetype_
{
if (self = [super init]) {
Expand Down