Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes AnimatedSprite component when images are updated #441

Merged
merged 5 commits into from
Sep 1, 2023
Merged
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
13 changes: 12 additions & 1 deletion packages/react/src/components/AnimatedSprite.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,21 @@
animatedSprite[isPlaying ? 'gotoAndPlay' : 'gotoAndStop'](initialFrame || 0);
animatedSprite.applyProps = (instance, oldProps, newProps) =>
{
const { textures, isPlaying, initialFrame, ...props } = newProps;
const { textures, isPlaying, initialFrame, images, ...props } = newProps;

let changed = applyDefaultProps(instance, oldProps, props);

if (images && oldProps.images !== images)
LukeWood marked this conversation as resolved.
Show resolved Hide resolved
LukeWood marked this conversation as resolved.
Show resolved Hide resolved
{
const newTextures = [];

Check warning on line 33 in packages/react/src/components/AnimatedSprite.js

View workflow job for this annotation

GitHub Actions / PR

Expected blank line after variable declarations
for (let i = 0; i < images.length; ++i)
{
newTextures.push(Texture.from(images[i]));
}
instance.textures = newTextures

Check warning on line 38 in packages/react/src/components/AnimatedSprite.js

View workflow job for this annotation

GitHub Actions / PR

Missing semicolon
changed = true;
}

if (textures && oldProps.textures !== textures)
{
instance.textures = makeTexture(textures);
Expand Down
8 changes: 7 additions & 1 deletion packages/react/test/element.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -148,12 +148,18 @@

test('AnimatedSprite.applyProps with images prop exists', () =>
{
const element = createElement(TYPES.AnimatedSprite, { images: ['./image.png'] });

Check warning on line 151 in packages/react/test/element.spec.js

View workflow job for this annotation

GitHub Actions / PR

Expected blank line after variable declarations

expect(element).toHaveProperty('applyProps');
expect(spy).lastCalledWith('./image.png');
});

test('AnimatedSprite.applyProps with updated image props', () =>
{
const element = createElement(TYPES.AnimatedSprite, { images: ['./image.png'] });
const changed = element.applyProps(element, { images: ['./image.png'] }, { images: ['./new-image.png'] });

Check warning on line 159 in packages/react/test/element.spec.js

View workflow job for this annotation

GitHub Actions / PR

Expected blank line after variable declarations
expect(spy).lastCalledWith('./new-image.png');
});

test('AnimatedSprite.applyProps with textures prop exists', () =>
{
const element = createElement(TYPES.AnimatedSprite, { textures: [Texture.from('./image.png')] });
Expand Down