Skip to content

Commit

Permalink
fix(ios)(8_2_X): sf symbol handling for application shortcut (#11222)
Browse files Browse the repository at this point in the history
* fix(ios): sf symbol handling for application shortcut

* fix(ios): updated doc

Co-Authored-By: Christopher Williams <chris.a.williams@gmail.com>

* fix(ios): enclosed function inside proper macro

* fix(ios): linting issue fixed
  • Loading branch information
vijaysingh-axway authored and ssekhri committed Sep 24, 2019
1 parent 6d4e417 commit b1d6ce0
Show file tree
Hide file tree
Showing 6 changed files with 64 additions and 4 deletions.
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"]) {
TiBlob *blob = (TiBlob *)value;
if (blob.type == TiBlobTypeSystemImage) {
return [UIApplicationShortcutIcon iconWithSystemImageName:blob.systemImageName];
}
}
#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"]) {
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

0 comments on commit b1d6ce0

Please sign in to comment.