Skip to content

Commit 0930972

Browse files
committed
fix(core): deprecated iOS APIs and four bugs found by strict typing
Compiling core to Swift rejects deprecated APIs and calls whose arguments do not match; each of these is a fix under the JavaScript runtime too. - image-source.ios: dispatch_get_current_queue (deprecated) gives way to the caller's operation queue, else main; base64Encoding to base64EncodedStringWithOptions(0). - dialogs.ios: presentModalViewControllerAnimated to presentViewControllerAnimatedCompletion. - tab-view.ios: UITextAttributeTextColor to NSForegroundColorAttributeName. - gestures.ios: TouchGestureEventData.getX/getY read contentOffset only from a UIScrollView (other views have none). - animation.ios: generateShadowLayerPaths takes the box shadow its layer draws; the animation called it without one (background.d.ts declares the parameter). - background-common: Background.equals compared the backgrounds, never gradients, instead of their images: gradient images now compare by value. - text-base.ios: clearing a text shadow sets a CGColor, not a UIColor, as the layer's shadowColor.
1 parent 5f2f9a9 commit 0930972

8 files changed

Lines changed: 22 additions & 20 deletions

File tree

‎packages/core/image-source/index.ios.ts‎

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,8 @@ export class ImageSource implements ImageSourceDefinition {
205205
return new Promise<ImageSource>((resolve, reject) => {
206206
try {
207207
const data = NSData.alloc().initWithBase64EncodedStringOptions(source, NSDataBase64DecodingOptions.IgnoreUnknownCharacters);
208-
const main_queue = dispatch_get_current_queue();
208+
// The caller's operation queue when it has one, else main: dispatch_get_current_queue is deprecated.
209+
const main_queue = NSOperationQueue.currentQueue?.underlyingQueue ?? NSOperationQueue.mainQueue.underlyingQueue;
209210
const background_queue = dispatch_get_global_queue(qos_class_t.QOS_CLASS_DEFAULT, 0);
210211
dispatch_async(background_queue, () => {
211212
const uiImage = UIImage.imageWithData(data);
@@ -380,7 +381,7 @@ export class ImageSource implements ImageSourceDefinition {
380381
if (quality) {
381382
quality = (quality - 0) / (100 - 0); // Normalize quality on a scale of 0 to 1
382383
}
383-
const main_queue = dispatch_get_current_queue();
384+
const main_queue = NSOperationQueue.currentQueue?.underlyingQueue ?? NSOperationQueue.mainQueue.underlyingQueue;
384385
const background_queue = dispatch_get_global_queue(qos_class_t.QOS_CLASS_DEFAULT, 0);
385386
dispatch_async(background_queue, () => {
386387
const data = getImageData(this.ios, format, quality);
@@ -409,7 +410,7 @@ export class ImageSource implements ImageSourceDefinition {
409410

410411
const data = getImageData(this.ios, format, quality);
411412
if (data) {
412-
res = data.base64Encoding();
413+
res = data.base64EncodedStringWithOptions(0 as NSDataBase64EncodingOptions);
413414
}
414415

415416
return res;
@@ -425,12 +426,12 @@ export class ImageSource implements ImageSourceDefinition {
425426
if (quality) {
426427
quality = (quality - 0) / (100 - 0); // Normalize quality on a scale of 0 to 1
427428
}
428-
const main_queue = dispatch_get_current_queue();
429+
const main_queue = NSOperationQueue.currentQueue?.underlyingQueue ?? NSOperationQueue.mainQueue.underlyingQueue;
429430
const background_queue = dispatch_get_global_queue(qos_class_t.QOS_CLASS_DEFAULT, 0);
430431
dispatch_async(background_queue, () => {
431432
const data = getImageData(this.ios, format, quality);
432433
if (data) {
433-
result = data.base64Encoding();
434+
result = data.base64EncodedStringWithOptions(0 as NSDataBase64EncodingOptions);
434435
}
435436
dispatch_async(main_queue, () => {
436437
resolve(result);
@@ -462,7 +463,7 @@ export class ImageSource implements ImageSourceDefinition {
462463
if (!this.ios) {
463464
reject(null);
464465
}
465-
const main_queue = dispatch_get_current_queue();
466+
const main_queue = NSOperationQueue.currentQueue?.underlyingQueue ?? NSOperationQueue.mainQueue.underlyingQueue;
466467
const background_queue = dispatch_get_global_queue(qos_class_t.QOS_CLASS_DEFAULT, 0);
467468
dispatch_async(background_queue, () => {
468469
const size: CGSize = this.ios.size;

‎packages/core/ui/animation/index.ios.ts‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -894,10 +894,11 @@ export class Animation extends AnimationBase {
894894

895895
const outerShadowLayers = nativeView.outerShadowContainerLayer.sublayers;
896896
if (outerShadowLayers?.count) {
897-
const { maskPath, shadowPath } = iosBackground.generateShadowLayerPaths(view, bounds);
897+
const boxShadows = view.style.backgroundInternal.getBoxShadows();
898898

899899
for (let i = 0, count = outerShadowLayers.count; i < count; i++) {
900900
const shadowLayer = outerShadowLayers[i];
901+
const { maskPath, shadowPath } = iosBackground.generateShadowLayerPaths(view, boxShadows[i], bounds);
901902

902903
shadowLayer.addAnimationForKey(
903904
this._createBasicAnimation(

‎packages/core/ui/dialogs/index.ios.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ function showUIAlertController(alertController: UIAlertController) {
8080
}
8181
}
8282

83-
viewController.presentModalViewControllerAnimated(alertController, true);
83+
viewController.presentViewControllerAnimatedCompletion(alertController, true, null);
8484
}
8585

8686
export function alert(arg: any): Promise<void> {

‎packages/core/ui/gestures/index.ios.ts‎

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -662,14 +662,14 @@ export class TouchGestureEventData {
662662
}
663663

664664
getX(): number {
665-
const offset = this.view.nativeViewProtected.contentOffset;
666-
const offsetX = offset ? offset.x : 0;
667-
return this.getMainPointer().locationInView(this.view.nativeViewProtected).x - offsetX;
665+
const nativeView = this.view.nativeViewProtected;
666+
const offsetX = nativeView instanceof UIScrollView ? nativeView.contentOffset.x : 0;
667+
return this.getMainPointer().locationInView(nativeView).x - offsetX;
668668
}
669669

670670
getY(): number {
671-
const offset = this.view.nativeViewProtected.contentOffset;
672-
const offsetY = offset ? offset.y : 0;
673-
return this.getMainPointer().locationInView(this.view.nativeViewProtected).y - offsetY;
671+
const nativeView = this.view.nativeViewProtected;
672+
const offsetY = nativeView instanceof UIScrollView ? nativeView.contentOffset.y : 0;
673+
return this.getMainPointer().locationInView(nativeView).y - offsetY;
674674
}
675675
}

‎packages/core/ui/styling/background-common.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -234,8 +234,8 @@ export class Background {
234234
}
235235

236236
let isImageEqual = false;
237-
if (value1 instanceof LinearGradient && value2 instanceof LinearGradient) {
238-
isImageEqual = LinearGradient.equals(value1, value2);
237+
if (value1.image instanceof LinearGradient && value2.image instanceof LinearGradient) {
238+
isImageEqual = LinearGradient.equals(value1.image, value2.image);
239239
} else {
240240
isImageEqual = value1.image === value2.image;
241241
}

‎packages/core/ui/styling/background.d.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ export namespace ios {
7979
export function clearBackgroundVisualEffects(view: View): void;
8080
export function createUIImageFromURI(view: View, imageURI: string, flip: boolean, callback: (image: any) => void): void;
8181
export function generateClipPath(view: View, bounds: any /* CGRect */): any;
82-
export function generateShadowLayerPaths(view: View, bounds: any /* CGRect */): { maskPath: any; shadowPath: any };
82+
export function generateShadowLayerPaths(view: View, boxShadow: BoxShadow, bounds: any /* CGRect */): { maskPath: any; shadowPath: any };
8383
export function getUniformBorderRadius(view: View, bounds: any /* CGRect */): number;
8484
export function generateNonUniformBorderInnerClipRoundedPath(view: View, bounds: any /* CGRect */): any;
8585
export function generateNonUniformBorderOuterClipRoundedPath(view: View, bounds: any /* CGRect */): any;

‎packages/core/ui/tab-view/index.ios.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1050,11 +1050,11 @@ function getTitleAttributesForStates(tabView: TabView): TabStates {
10501050

10511051
const titleColor = tabView.style.tabTextColor;
10521052
if (titleColor instanceof Color) {
1053-
result.normalState.setValueForKey(titleColor.ios, UITextAttributeTextColor);
1053+
result.normalState.setValueForKey(titleColor.ios, NSForegroundColorAttributeName);
10541054
}
10551055
const selectedTitleColor = tabView.style.selectedTabTextColor;
10561056
if (selectedTitleColor instanceof Color) {
1057-
result.selectedState.setValueForKey(selectedTitleColor.ios, UITextAttributeTextColor);
1057+
result.selectedState.setValueForKey(selectedTitleColor.ios, NSForegroundColorAttributeName);
10581058
}
10591059

10601060
return result;

‎packages/core/ui/text-base/index.ios.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -479,7 +479,7 @@ export class TextBase extends TextBaseCommon {
479479
// clear the text shadow
480480
layer.shadowOpacity = 0;
481481
layer.shadowRadius = 0;
482-
layer.shadowColor = UIColor.clearColor;
482+
layer.shadowColor = UIColor.clearColor.CGColor;
483483
layer.shadowOffset = CGSizeMake(0, 0);
484484
return;
485485
}

0 commit comments

Comments
 (0)