Skip to content

Commit f7c4b99

Browse files
authored
Merge pull request #58 from nativescript-community/add-loading-to-ios
Add loading to ios
2 parents 74b1253 + e9b221f commit f7c4b99

File tree

5 files changed

+41
-6
lines changed

5 files changed

+41
-6
lines changed

demo-snippets/vue/Simple.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
<GridLayout rows="300, auto, auto, auto, auto, auto">
88
<StackLayout orientation="horizontal">
9-
<NSImg backgroundColor="yellow" height="500" ref="opacityImg" borderRadius="10" width="50%" src="~/assets/images/dessert.jpg" stretch="aspectFit" />
9+
<NSImg :showProgressBar="true" progressBarColor="green" backgroundColor="yellow" height="500" ref="opacityImg" borderRadius="10" width="50%" src="https://images.pexels.com/photos/842711/pexels-photo-842711.jpeg" stretch="aspectFit" />
1010
<NSImg backgroundColor="red" width="50%" height="100" verticalAlignment="center" borderRadius="100" :src="imgSource"> </NSImg>
1111
</StackLayout>
1212
<WrapLayout row="1">

packages/image/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -448,15 +448,15 @@ Boolean value used for enabling or disabling the streaming of progressive JPEG i
448448
<@nativescript-community/ui-image:Img progressiveRenderingEnabled="true"/>
449449
```
450450

451-
- **showProgressBar** (Android only)
451+
- **showProgressBar**
452452

453453
Boolean value used for showing or hiding the progress bar.
454454

455455
```xml
456456
<@nativescript-community/ui-image:Img showProgressBar="true"/>
457457
```
458458

459-
- **progressBarColor** (Android only)
459+
- **progressBarColor**
460460

461461
String value used for setting the color of the progress bar. You can set it to hex values ("*#FF0000*") and/or predefined colors ("*green*").
462462

packages/image/blueprint.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -381,15 +381,15 @@ Boolean value used for enabling or disabling the streaming of progressive JPEG i
381381
<@nativescript-community/ui-image:Img progressiveRenderingEnabled="true"/>
382382
```
383383

384-
- **showProgressBar** (Android only)
384+
- **showProgressBar**
385385

386386
Boolean value used for showing or hiding the progress bar.
387387

388388
```xml
389389
<@nativescript-community/ui-image:Img showProgressBar="true"/>
390390
```
391391

392-
- **progressBarColor** (Android only)
392+
- **progressBarColor**
393393

394394
String value used for setting the color of the progress bar. You can set it to hex values ("*#FF0000*") and/or predefined colors ("*green*").
395395

src/image/index.ios.ts

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
export * from './index-common';
2-
import { ImageAsset, ImageSource, Screen, Trace, Utils, knownFolders, path } from '@nativescript/core';
2+
import { Color, ImageAsset, ImageSource, Screen, Trace, Utils, knownFolders, path } from '@nativescript/core';
33
import { layout } from '@nativescript/core/utils/layout-helper';
44
import { isString } from '@nativescript/core/utils/types';
55
import {
@@ -15,6 +15,8 @@ import {
1515
failureImageUriProperty,
1616
imageRotationProperty,
1717
placeholderImageUriProperty,
18+
progressBarColorProperty,
19+
showProgressBarProperty,
1820
srcProperty,
1921
stretchProperty,
2022
wrapNativeException
@@ -521,6 +523,21 @@ export class Img extends ImageBase {
521523
});
522524
}
523525
this.mCacheKey = SDWebImageManager.sharedManager.cacheKeyForURLContext(uri, context);
526+
if (this.showProgressBar) {
527+
try{
528+
if (this.progressBarColor && Color.isValid(this.progressBarColor)) {
529+
const indicator = new SDWebImageActivityIndicator();
530+
indicator.indicatorView.color = new Color(this.progressBarColor).ios;
531+
this.nativeImageViewProtected.sd_imageIndicator = indicator;
532+
} else {
533+
this.nativeImageViewProtected.sd_imageIndicator = SDWebImageActivityIndicator.grayIndicator;
534+
}
535+
}
536+
catch(ex) {
537+
console.error(ex)
538+
}
539+
}
540+
524541
this.nativeImageViewProtected.sd_setImageWithURLPlaceholderImageOptionsContextProgressCompleted(
525542
uri,
526543
this.placeholderImage,
@@ -551,6 +568,22 @@ export class Img extends ImageBase {
551568
// this.initImage();
552569
}
553570

571+
[showProgressBarProperty.getDefault](): boolean {
572+
return false;
573+
}
574+
575+
[showProgressBarProperty.setNative](value) {
576+
this.showProgressBar = value;
577+
}
578+
579+
[progressBarColorProperty.getDefault](): string {
580+
return "";
581+
}
582+
583+
[progressBarColorProperty.setNative](value) {
584+
this.progressBarColor = value;
585+
}
586+
554587
[failureImageUriProperty.setNative]() {
555588
// this.updateHierarchy();
556589
}

src/image/typings/ios.d.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ declare namespace NSURL {
66
export function sd_URLWithAssetLocalIdentifier(identifier: string): NSURL;
77
}
88
declare interface UIImageView {
9+
sd_imageIndicator: SDWebImageIndicator;
10+
911
sd_setHighlightedImageWithURL(url: NSURL): void;
1012

1113
sd_setHighlightedImageWithURLCompleted(url: NSURL, completedBlock: (p1: UIImage, p2: NSError, p3: SDImageCacheType, p4: NSURL) => void): void;

0 commit comments

Comments
 (0)