diff --git a/NativeScript/embedding/NativeScriptEmbedder.h b/NativeScript/embedding/NativeScriptEmbedder.h deleted file mode 100644 index 1a35943b..00000000 --- a/NativeScript/embedding/NativeScriptEmbedder.h +++ /dev/null @@ -1,26 +0,0 @@ -// -// NativeScriptEmbedder.h -// NativeScript -// -// Created by Teodor Dermendzhiev on 6/19/18. -// -#include - -// When embedding NativeScript application embedder needs to conform to this protocol -// in order to have control over the NativeScript UIViewController -// otherwise NativeScript application is presented over the topmost UIViewController. -@protocol NativeScriptEmbedderDelegate -- (id)presentNativeScriptApp:(UIViewController*)vc; -@end - -@interface NativeScriptEmbedder : NSObject - -@property(nonatomic, retain, readonly) id delegate; - -+ (NativeScriptEmbedder *)sharedInstance; - -- (void)setDelegate:(id )aDelegate; - - -@end - diff --git a/NativeScript/embedding/NativeScriptEmbedder.m b/NativeScript/embedding/NativeScriptEmbedder.m deleted file mode 100644 index 6d6bfa55..00000000 --- a/NativeScript/embedding/NativeScriptEmbedder.m +++ /dev/null @@ -1,19 +0,0 @@ -#import "NativeScriptEmbedder.h" - -@implementation NativeScriptEmbedder - -+ (NativeScriptEmbedder *)sharedInstance { - static NativeScriptEmbedder *sharedInstance = nil; - static dispatch_once_t onceToken; - dispatch_once(&onceToken, ^{ - sharedInstance = [[NativeScriptEmbedder alloc] init]; - }); - - return sharedInstance; -} - -- (void)setDelegate:(id )aDelegate { - _delegate = aDelegate; -} - -@end diff --git a/NativeScript/embedding/NativeScriptSDK.h b/NativeScript/embedding/NativeScriptSDK.h deleted file mode 100644 index fd08b0d7..00000000 --- a/NativeScript/embedding/NativeScriptSDK.h +++ /dev/null @@ -1,3 +0,0 @@ -#import "NativeScriptEmbedder.h" -#import "NativeScriptUtils.h" -#import "UIView+NativeScript.h" diff --git a/NativeScript/embedding/NativeScriptUtils.h b/NativeScript/embedding/NativeScriptUtils.h deleted file mode 100644 index e741b10d..00000000 --- a/NativeScript/embedding/NativeScriptUtils.h +++ /dev/null @@ -1,16 +0,0 @@ -// -// NativeScriptUtils.h -// -// Created by Nathan Walker on 2/02/2022. -#include - -@interface NativeScriptUtils : NSObject - -+(UIFont*) getSystemFont:(CGFloat)size weight:(UIFontWeight)weight italic:(BOOL)italic symbolicTraits:(UIFontDescriptorSymbolicTraits)symbolicTraits; -+(UIFont*) createUIFont:(NSDictionary*)font; -+(NSMutableAttributedString*)createMutableStringWithDetails:(NSDictionary*)details; -+(NSMutableAttributedString*)createMutableStringForSpan:(NSString*)text font:(UIFont*)font color:(UIColor*)color backgroundColor:(UIColor*)backgroundColor textDecoration:(NSString*)textDecoration baselineOffset:(CGFloat)baselineOffset; -+(UIImage*)scaleImage:(UIImage*)image width:(CGFloat)width height:(CGFloat)height scaleFactor:(CGFloat)scaleFactor; -+(NSData*)getImageData:(UIImage*)image format:(NSString*)format quality:(CGFloat)quality; - -@end diff --git a/NativeScript/embedding/NativeScriptUtils.m b/NativeScript/embedding/NativeScriptUtils.m deleted file mode 100644 index ace5af11..00000000 --- a/NativeScript/embedding/NativeScriptUtils.m +++ /dev/null @@ -1,137 +0,0 @@ -#import "NativeScriptUtils.h" - -@implementation NativeScriptUtils - -+(UIFont*) getSystemFont:(CGFloat)size weight:(UIFontWeight)weight italic:(BOOL)italic symbolicTraits:(UIFontDescriptorSymbolicTraits)symbolicTraits { - UIFont *result = [UIFont systemFontOfSize:size weight:weight]; - if (italic) { - result = [UIFont fontWithDescriptor:[result.fontDescriptor fontDescriptorWithSymbolicTraits:symbolicTraits] size:size]; - } - - return result; -} -+(UIFont*) createUIFont:(NSDictionary*)font { - UIFont *result; - - CGFloat size = [[font valueForKey:@"fontSize"] floatValue]; - - UIFontDescriptorSymbolicTraits symbolicTraits = 0; - if ([[font valueForKey:@"isBold"] boolValue]) { - symbolicTraits = symbolicTraits | UIFontDescriptorTraitBold; - } - if ([[font valueForKey:@"isItalic"] boolValue]) { - symbolicTraits = symbolicTraits | UIFontDescriptorTraitItalic; - } - - NSDictionary *fontDescriptorTraits = @{ - UIFontSymbolicTrait : @(symbolicTraits), - UIFontWeightTrait : [font valueForKey:@"fontWeight"] - }; - - for (NSString *family in [NSArray arrayWithArray:[font valueForKey:@"fontFamily"]]) { - NSString *fontFamily = family; - if ([family.lowercaseString isEqualToString:@"serif"]) { - fontFamily = @"Times New Roman"; - } else if ([family.lowercaseString isEqualToString:@"monospace"]) { - fontFamily = @"Courier New"; - } - - if (!fontFamily || [fontFamily isEqualToString:@"sans-serif"] || [fontFamily isEqualToString:@"system"]) { - result = [NativeScriptUtils getSystemFont:size weight:(UIFontWeight)[[font valueForKey:@"fontWeight"] floatValue] italic:[[font valueForKey:@"isItalic"] boolValue] symbolicTraits:symbolicTraits]; - break; - } else { - UIFontDescriptor *descriptor = [UIFontDescriptor fontDescriptorWithFontAttributes:@{ - UIFontDescriptorFamilyAttribute: fontFamily, - UIFontDescriptorTraitsAttribute: fontDescriptorTraits - }]; - - result = [UIFont fontWithDescriptor:descriptor size:size]; - - BOOL actualItalic = result.fontDescriptor.symbolicTraits & UIFontDescriptorTraitItalic; - if ([[font valueForKey:@"isItalic"] boolValue] && !actualItalic) { - #if TARGET_OS_MACCATALYST - #else - // The font we got is not actually italic so emulate that with a matrix - result = [UIFont fontWithDescriptor:[descriptor fontDescriptorWithMatrix:CGAffineTransformMake(1, 0, 0.2, 1, 0, 0)] size:size]; - #endif - } - - // Check if the resolved font has the correct font-family - // If not - fallback to the next font-family - if ([result.familyName isEqualToString:fontFamily]) { - break; - } else { - result = nil; - } - } - } - - // Couldn't resolve font - fallback to the system font - if (result == nil) { - result = [NativeScriptUtils getSystemFont:size weight:(UIFontWeight)[[font valueForKey:@"fontWeight"] floatValue] italic:[[font valueForKey:@"isItalic"] boolValue] symbolicTraits:symbolicTraits]; - } - - return result; -} - -+(NSMutableAttributedString*)createMutableStringWithDetails:(NSDictionary*)details { - NSMutableAttributedString *mas = [[NSMutableAttributedString alloc] init]; - for (NSDictionary *detail in [NSArray arrayWithArray:[details valueForKey:@"spans"]]) { - NSMutableAttributedString *attrString = [NativeScriptUtils createMutableStringForSpan:[detail objectForKey:@"text"] font:[detail objectForKey:@"iosFont"] color:[detail objectForKey:@"color"] backgroundColor:[detail objectForKey:@"backgroundColor"] textDecoration:[detail objectForKey:@"textDecoration"] baselineOffset:[[detail valueForKey:@"baselineOffset"] floatValue]]; - [mas insertAttributedString:attrString atIndex:[[detail valueForKey:@"index"] intValue]]; - } - return mas; -} - -+(NSMutableAttributedString*)createMutableStringForSpan:(NSString*)text font:(UIFont*)font color:(UIColor*)color backgroundColor:(UIColor*)backgroundColor textDecoration:(NSString*)textDecoration baselineOffset:(CGFloat)baselineOffset { - NSMutableDictionary *attrDict = [[NSMutableDictionary alloc] init]; - attrDict[NSFontAttributeName] = font; - - if (color != nil) { - attrDict[NSForegroundColorAttributeName] = color; - } - - if (backgroundColor != nil) { - attrDict[NSBackgroundColorAttributeName] = backgroundColor; - } - - if (textDecoration != nil) { - if ([textDecoration rangeOfString:@"underline"].location != NSNotFound) { - attrDict[NSUnderlineStyleAttributeName] = [NSNumber numberWithInt:NSUnderlineStyleSingle]; - } - - if ([textDecoration rangeOfString:@"line-through"].location != NSNotFound) { - attrDict[NSStrikethroughStyleAttributeName] = [NSNumber numberWithInt:NSUnderlineStyleSingle]; - } - } - - attrDict[NSBaselineOffsetAttributeName] = [NSNumber numberWithInt:baselineOffset]; - - return [[NSMutableAttributedString alloc] initWithString:text attributes:attrDict]; - -} - -+(UIImage*)scaleImage:(UIImage*)image width:(CGFloat)width height:(CGFloat)height scaleFactor:(CGFloat)scaleFactor { - UIImage *resultImage; - @autoreleasepool { - UIGraphicsBeginImageContextWithOptions(CGSizeMake(width, height), NO, scaleFactor); - [image drawInRect:CGRectMake(0, 0, width, height)]; - resultImage = UIGraphicsGetImageFromCurrentImageContext(); - UIGraphicsEndImageContext(); - } - return resultImage; -} - -+(NSData*)getImageData:(UIImage*)image format:(NSString*)format quality:(CGFloat)quality { - NSData *data; - @autoreleasepool { - if ([format.lowercaseString isEqualToString:@"png"]) { - data = UIImagePNGRepresentation(image); - } else { - data = UIImageJPEGRepresentation(image, quality); - } - } - return data; -} - -@end diff --git a/NativeScript/embedding/UIView+NativeScript.h b/NativeScript/embedding/UIView+NativeScript.h deleted file mode 100644 index 1ee32f0a..00000000 --- a/NativeScript/embedding/UIView+NativeScript.h +++ /dev/null @@ -1,13 +0,0 @@ -// -// UIView+NativeScript.h -// -// Created by Nathan Walker on 2/02/2022. -#include - -@interface UIView (NativeScript) - -- (void)nativeScriptSetTextDecorationAndTransform:(NSString*)text textDecoration:(NSString*)textDecoration letterSpacing:(CGFloat)letterSpacing lineHeight:(CGFloat)lineHeight; - --(void)nativeScriptSetFormattedTextDecorationAndTransform:(NSDictionary*)details letterSpacing:(CGFloat)letterSpacing lineHeight:(CGFloat)lineHeight; - -@end diff --git a/NativeScript/embedding/UIView+NativeScript.m b/NativeScript/embedding/UIView+NativeScript.m deleted file mode 100644 index 51485226..00000000 --- a/NativeScript/embedding/UIView+NativeScript.m +++ /dev/null @@ -1,133 +0,0 @@ -#import -#import "UIView+NativeScript.h" -#import "NativeScriptUtils.h" - -@implementation UIView (NativeScript) -- (void)nativeScriptSetTextDecorationAndTransform:(NSString*)text textDecoration:(NSString*)textDecoration letterSpacing:(CGFloat)letterSpacing lineHeight:(CGFloat)lineHeight { - NSMutableDictionary *attrDict = [[NSMutableDictionary alloc] init]; - - if ([textDecoration rangeOfString:@"underline"].location != NSNotFound) { - attrDict[NSUnderlineStyleAttributeName] = [NSNumber numberWithInt:NSUnderlineStyleSingle]; - } - - if ([textDecoration rangeOfString:@"line-through"].location != NSNotFound) { - attrDict[NSStrikethroughStyleAttributeName] = [NSNumber numberWithInt:NSUnderlineStyleSingle]; - } - BOOL isTextType = [self isKindOfClass:[UITextField class]] || [self isKindOfClass:[UITextView class]] | [self isKindOfClass:[UILabel class]] | [self isKindOfClass:[UIButton class]]; - - if (letterSpacing != 0 && isTextType && ((UITextView*)self).font != nil) { - NSNumber *kern = [NSNumber numberWithDouble:letterSpacing * ((UITextView*)self).font.pointSize]; - attrDict[NSKernAttributeName] = kern; - if ([self isKindOfClass:[UITextField class]]) { - [((UITextField*)self).defaultTextAttributes setValue:kern forKey:NSKernAttributeName]; - } - } - - BOOL isTextView = [self isKindOfClass:[UITextView class]]; - if (lineHeight > 0) { - NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc] init]; - paragraphStyle.lineSpacing = lineHeight; - // make sure a possible previously set text alignment setting is not lost when line height is specified - if ([self isKindOfClass:[UIButton class]]) { - paragraphStyle.alignment = ((UIButton*)self).titleLabel.textAlignment; - } else { - paragraphStyle.alignment = ((UILabel*)self).textAlignment; - } - - if ([self isKindOfClass:[UILabel class]]) { - // make sure a possible previously set line break mode is not lost when line height is specified - paragraphStyle.lineBreakMode = ((UILabel*)self).lineBreakMode; - } - attrDict[NSParagraphStyleAttributeName] = paragraphStyle; - } else if (isTextView) { - NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc] init]; - paragraphStyle.alignment = ((UITextView*)self).textAlignment; - attrDict[NSParagraphStyleAttributeName] = paragraphStyle; - } - - if (attrDict.count > 0 || isTextView) { - if (isTextView && ((UITextView*)self).font) { - // UITextView's font seems to change inside. - attrDict[NSFontAttributeName] = ((UITextView*)self).font; - } - - NSMutableAttributedString *result = [[NSMutableAttributedString alloc] initWithString:text]; - [result setAttributes:attrDict range:(NSRange){ - 0, - text.length - }]; - - if ([self isKindOfClass:[UIButton class]]) { - [(UIButton*)self setAttributedTitle:result forState:UIControlStateNormal]; - } else { - ((UITextView*)self).attributedText = result; - } - } else { - if ([self isKindOfClass:[UIButton class]]) { - // Clear attributedText or title won't be affected. - [(UIButton*)self setAttributedTitle:nil forState:UIControlStateNormal]; - [(UIButton*)self setTitle:text forState:UIControlStateNormal]; - } else { - // Clear attributedText or text won't be affected. - ((UILabel*)self).attributedText = nil; - ((UILabel*)self).text = text; - } - } -} - --(void)nativeScriptSetFormattedTextDecorationAndTransform:(NSDictionary*)details letterSpacing:(CGFloat)letterSpacing lineHeight:(CGFloat)lineHeight { - NSMutableAttributedString *attrText = [NativeScriptUtils createMutableStringWithDetails:details]; - if (letterSpacing != 0) { - NSNumber *kern = [NSNumber numberWithDouble:letterSpacing * ((UITextView*)self).font.pointSize]; - [attrText addAttribute:NSKernAttributeName value:kern range:(NSRange){ - 0, - attrText.length - } ]; - } - - BOOL isLabel = [self isKindOfClass:[UILabel class]]; - if (lineHeight > 0) { - NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc] init]; - paragraphStyle.lineSpacing = lineHeight; - // make sure a possible previously set text alignment setting is not lost when line height is specified - if ([self isKindOfClass:[UIButton class]]) { - paragraphStyle.alignment = ((UIButton*)self).titleLabel.textAlignment; - } else { - // Paragraph alignment is also important for tappable spans as NSTextContainer takes it into account - paragraphStyle.alignment = ((UILabel*)self).textAlignment; - } - - if (isLabel) { - // make sure a possible previously set line break mode is not lost when line height is specified - paragraphStyle.lineBreakMode = ((UILabel*)self).lineBreakMode; - } - [attrText addAttribute:NSParagraphStyleAttributeName value:paragraphStyle range:(NSRange){ - 0, - attrText.length - }]; - } else if (isLabel || [self isKindOfClass:[UITextView class]]) { - NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc] init]; - - if (isLabel) { - // It's important to set paragraph alignment for link tap to work on multi-line spans as NSTextContainer takes it into account - paragraphStyle.alignment = ((UILabel*)self).textAlignment; - } else { - paragraphStyle.alignment = ((UITextView*)self).textAlignment; - } - [attrText addAttribute:NSParagraphStyleAttributeName value:paragraphStyle range:(NSRange){ - 0, - attrText.length - }]; - } - - if ([self isKindOfClass:[UIButton class]]) { - [(UIButton*)self setAttributedTitle:attrText forState:UIControlStateNormal]; - } else { - if (@available(iOS 13.0, *)) { - ((UILabel*)self).textColor = [UIColor labelColor]; - } - - ((UILabel*)self).attributedText = attrText; - } -} -@end diff --git a/NativeScript/embedding/module.modulemap b/NativeScript/embedding/module.modulemap deleted file mode 100644 index 8eda4c2b..00000000 --- a/NativeScript/embedding/module.modulemap +++ /dev/null @@ -1,4 +0,0 @@ -module NativeScriptSDK { - umbrella header "NativeScriptSDK.h" - export * -}