Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions apps/toolbox/src/pages/image-handling.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,16 @@ export function navigatingTo(args: EventData) {

export class DemoModel extends Observable {
addingPhoto = false;
tintTestSrc = 'res://icon';
symbolWiggleEffect = ImageSymbolEffects.Wiggle;
symbolBounceEffect = ImageSymbolEffects.Bounce;
symbolBreathEffect = ImageSymbolEffects.Breathe;
symbolRotateEffect = ImageSymbolEffects.Rotate;

toggleTintTestSrc() {
this.set('tintTestSrc', this.tintTestSrc === 'res://icon' ? 'res://add_to_fav' : 'res://icon');
}

pickImage() {
const context = create({
mode: 'single',
Expand Down
13 changes: 13 additions & 0 deletions apps/toolbox/src/pages/image-handling.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,19 @@

<StackLayout class="p-20">

<Label text="tintColor + dynamic src" class="h2" />
<Label text="Tap the image to swap src between icon and add_to_fav. The red tint should persist after each swap." textWrap="true" />
<GridLayout columns="auto, *, auto" rows="auto" class="m-t-10 m-b-10">
<Image col="0" src="{{ tintTestSrc }}" tintColor="#E53935" width="80" height="80" tap="{{ toggleTintTestSrc }}" stretch="aspectFit" />
<StackLayout col="1" verticalAlignment="center" class="m-l-10">
<Label text="{{ 'src: ' + tintTestSrc }}" textWrap="true" />
<Label text="tintColor: #E53935" />
<Label text="(tap image to toggle)" class="footnote" />
</StackLayout>
</GridLayout>

<ContentView height="1" width="100%" backgroundColor="#efefef" margin="10" />

<Label text="Test Memory leaks with image picking and saving to device. Best to profile from platform IDE like Xcode." textWrap="true" />

<Button text="Pick and Save Image" tap="{{ pickImage }}" />
Expand Down
11 changes: 11 additions & 0 deletions packages/core/ui/image/index.android.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ function initializeImageLoadedListener() {
const owner = this.owner;
if (owner) {
owner.isLoading = false;
if (success) {
owner._reapplyTintColor();
}
}
}
}
Expand Down Expand Up @@ -78,6 +81,13 @@ export class Image extends ImageBase {
this.nativeViewProtected.setImageMatrix(new android.graphics.Matrix());
}

public _reapplyTintColor(): void {
const tintColor = this.style?.tintColor;
if (tintColor && this.nativeViewProtected) {
this.nativeViewProtected.setColorFilter(tintColor.android);
}
}

public _createImageSourceFromSrc(value: string | ImageSource | ImageAsset) {
const imageView = this.nativeViewProtected;
if (!imageView) {
Expand Down Expand Up @@ -181,6 +191,7 @@ export class Image extends ImageBase {
nativeView.setRotationAngle(0);
nativeView.setImageBitmap(null);
}
this._reapplyTintColor();
}

[srcProperty.getDefault](): any {
Expand Down
Loading