mirror of
https://github.com/rive-app/rive-react.git
synced 2026-03-13 08:22:30 +08:00
Compare commits
134 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
09c0d1f947 | ||
|
|
0ca5933c41 | ||
|
|
f272fd92f0 | ||
|
|
192a562764 | ||
|
|
224a768737 | ||
|
|
c085bd5ea3 | ||
|
|
bb13c71982 | ||
|
|
779e06583c | ||
|
|
e172e0f210 | ||
|
|
abbcf14b70 | ||
|
|
a0885648ce | ||
|
|
9f768bdd0c | ||
|
|
94c9a2a60b | ||
|
|
dfe0d10936 | ||
|
|
d27eb7254d | ||
|
|
c0b27bd018 | ||
|
|
739ac7c370 | ||
|
|
b1b8040b4f | ||
|
|
1f6ae83de3 | ||
|
|
e5ff233c34 | ||
|
|
64795564d8 | ||
|
|
f0b32056a4 | ||
|
|
b5dc2fa8da | ||
|
|
0108d425dd | ||
|
|
74a27143b4 | ||
|
|
2cfb8a4955 | ||
|
|
af6c3f84c6 | ||
|
|
351d9966b1 | ||
|
|
ba73cb7053 | ||
|
|
4a4f8a7151 | ||
|
|
b5baef5ce7 | ||
|
|
79f80d39cd | ||
|
|
e1ed8250e3 | ||
|
|
a40ba0dacc | ||
|
|
7ea9c8fbcb | ||
|
|
d4cef9a131 | ||
|
|
99489af287 | ||
|
|
d881bb18c8 | ||
|
|
2e461c66b3 | ||
|
|
bb078296d0 | ||
|
|
f9bad8b62d | ||
|
|
e42f5e32d7 | ||
|
|
83fa6635ec | ||
|
|
bdd4c84d8b | ||
|
|
414543d37d | ||
|
|
119f7eea2a | ||
|
|
92b0342882 | ||
|
|
38b0a1cc86 | ||
|
|
2fd87e45e8 | ||
|
|
dc99fe27cc | ||
|
|
2358c82626 | ||
|
|
0475d47535 | ||
|
|
f51e538479 | ||
|
|
29fa6e76fb | ||
|
|
2459c489bf | ||
|
|
927dbc6b32 | ||
|
|
8ebbfb164f | ||
|
|
388fd16b5b | ||
|
|
8c87bc0ab7 | ||
|
|
280b2ec4a4 | ||
|
|
55a40c7d9f | ||
|
|
d4e6243dbb | ||
|
|
dc738d00a6 | ||
|
|
2ae22d6c30 | ||
|
|
4a3fc22261 | ||
|
|
bdc734b90b | ||
|
|
eeda717178 | ||
|
|
178f04df61 | ||
|
|
ef11079784 | ||
|
|
11f548b21c | ||
|
|
d0ff23c124 | ||
|
|
a83f5a275a | ||
|
|
b437230063 | ||
|
|
10912052f2 | ||
|
|
fe8265cd58 | ||
|
|
5b458b76e5 | ||
|
|
1decbc7d85 | ||
|
|
87627125f5 | ||
|
|
e823e9519f | ||
|
|
ac88187118 | ||
|
|
1897e823b9 | ||
|
|
1a2e57a82c | ||
|
|
0d16feeec1 | ||
|
|
ca48907649 | ||
|
|
9b02c0f1bc | ||
|
|
b25c775994 | ||
|
|
17811adac4 | ||
|
|
e4fcef529e | ||
|
|
f51fe6ee2a | ||
|
|
0f558e66e1 | ||
|
|
7a67fb14f7 | ||
|
|
da3fc317ff | ||
|
|
9b40a1a02e | ||
|
|
aa92c01329 | ||
|
|
99a8a42a15 | ||
|
|
f0ea7add89 | ||
|
|
ac9f322ccb | ||
|
|
e1c2d108e9 | ||
|
|
3aaee0bcf8 | ||
|
|
e3739f1a1f | ||
|
|
0e0a2bd972 | ||
|
|
5c47a411f2 | ||
|
|
16dc257b2f | ||
|
|
4678ea9ecf | ||
|
|
d58963e29d | ||
|
|
c32433284a | ||
|
|
8bb5652df0 | ||
|
|
9ecacf37fe | ||
|
|
f837fbe0d4 | ||
|
|
8e181d6ae2 | ||
|
|
a3a41dca40 | ||
|
|
b78c9715d7 | ||
|
|
520e5bb51d | ||
|
|
586ee4c002 | ||
|
|
3d6c7ed499 | ||
|
|
c3900b7845 | ||
|
|
d369817113 | ||
|
|
d68302ccb3 | ||
|
|
bbd4cc7af6 | ||
|
|
3936277f65 | ||
|
|
aa2a783d1c | ||
|
|
d8d7d64749 | ||
|
|
af3edad2c2 | ||
|
|
5326f800f7 | ||
|
|
b44f9ad9e1 | ||
|
|
b2495300b7 | ||
|
|
eb436263d7 | ||
|
|
0e6385288e | ||
|
|
78f75434fc | ||
|
|
a9c2950419 | ||
|
|
e799f64554 | ||
|
|
95a1daa4ef | ||
|
|
8a5b88c591 | ||
|
|
d3b29cf7d7 |
407
CHANGELOG.md
407
CHANGELOG.md
@@ -4,11 +4,416 @@ All notable changes to this project will be documented in this file. Dates are d
|
||||
|
||||
Generated by [`auto-changelog`](https://github.com/CookPete/auto-changelog).
|
||||
|
||||
#### [v4.17.8](https://github.com/rive-app/rive-react/compare/v4.17.7...v4.17.8)
|
||||
|
||||
- update rive to 2.25.6 [`0ca5933`](https://github.com/rive-app/rive-react/commit/0ca5933c411b1a733b35dd785a7bfcdba569b8c5)
|
||||
|
||||
#### [v4.17.7](https://github.com/rive-app/rive-react/compare/v4.17.6...v4.17.7)
|
||||
|
||||
> 23 January 2025
|
||||
|
||||
- chore: release 4.17.7 [`f272fd9`](https://github.com/rive-app/rive-react/commit/f272fd92f0030016b691923f8c61d1ae56182e82)
|
||||
- chore: bump wasm to 2.25.5 [`192a562`](https://github.com/rive-app/rive-react/commit/192a562764d1cb906d14e2f8f3d6fed3cfa5f039)
|
||||
|
||||
#### [v4.17.6](https://github.com/rive-app/rive-react/compare/v4.17.5...v4.17.6)
|
||||
|
||||
> 14 January 2025
|
||||
|
||||
- chore: release 4.17.6 [`224a768`](https://github.com/rive-app/rive-react/commit/224a7687373bfc8ef05bfb4604f5b1e2be9e4cdd)
|
||||
- update rive to 2.25.4 [`c085bd5`](https://github.com/rive-app/rive-react/commit/c085bd5ea3c811a5934c725d3347baf723b11225)
|
||||
|
||||
#### [v4.17.5](https://github.com/rive-app/rive-react/compare/v4.17.4...v4.17.5)
|
||||
|
||||
> 24 December 2024
|
||||
|
||||
- chore: release 4.17.5 [`bb13c71`](https://github.com/rive-app/rive-react/commit/bb13c719828b2c5c27b524f0e79b5f7ad3896618)
|
||||
- bump rive canvas to 2.25.3 [`779e065`](https://github.com/rive-app/rive-react/commit/779e06583ceb853621693d0e0c056537c90998b9)
|
||||
|
||||
#### [v4.17.4](https://github.com/rive-app/rive-react/compare/v4.17.3...v4.17.4)
|
||||
|
||||
> 17 December 2024
|
||||
|
||||
- chore: release 4.17.4 [`e172e0f`](https://github.com/rive-app/rive-react/commit/e172e0f21092a3c4dd9cf528aa71684dc07b3fa7)
|
||||
- rive canvas 2.25.2 [`abbcf14`](https://github.com/rive-app/rive-react/commit/abbcf14b706fedb8aed1c291b0d35b225206eed8)
|
||||
|
||||
#### [v4.17.3](https://github.com/rive-app/rive-react/compare/v4.17.2...v4.17.3)
|
||||
|
||||
> 13 December 2024
|
||||
|
||||
- chore: release 4.17.3 [`a088564`](https://github.com/rive-app/rive-react/commit/a0885648ceb4d833c1467fd10d36641fc5f79450)
|
||||
- rive canvas 2.25.1 [`9f768bd`](https://github.com/rive-app/rive-react/commit/9f768bdd0ca07aedec7f67405223b44bcf7380d7)
|
||||
|
||||
#### [v4.17.2](https://github.com/rive-app/rive-react/compare/v4.17.1...v4.17.2)
|
||||
|
||||
> 11 December 2024
|
||||
|
||||
- chore: release 4.17.2 [`94c9a2a`](https://github.com/rive-app/rive-react/commit/94c9a2a60b89244e0a36eb9324e500616a31e970)
|
||||
- rive canvas 2.25.0 [`dfe0d10`](https://github.com/rive-app/rive-react/commit/dfe0d109368abe8ebadf8dabc80d05116242c301)
|
||||
|
||||
#### [v4.17.1](https://github.com/rive-app/rive-react/compare/v4.17.0...v4.17.1)
|
||||
|
||||
> 11 December 2024
|
||||
|
||||
- chore: release 4.17.1 [`d27eb72`](https://github.com/rive-app/rive-react/commit/d27eb7254dfa2c2338f02264c7d1a65c8bf1f366)
|
||||
- rive canvas 2.24.1 [`c0b27bd`](https://github.com/rive-app/rive-react/commit/c0b27bd018f0bdb6f0e1679816c96c5ba6d6c5bd)
|
||||
|
||||
#### [v4.17.0](https://github.com/rive-app/rive-react/compare/v4.16.7...v4.17.0)
|
||||
|
||||
> 10 December 2024
|
||||
|
||||
- chore: release 4.17.0 [`739ac7c`](https://github.com/rive-app/rive-react/commit/739ac7c3708b7aa28d0bae01fc13ce99d7fc27ed)
|
||||
- bump rive canvas to 2.24.0 [`b1b8040`](https://github.com/rive-app/rive-react/commit/b1b8040b4f92375be734070502e73e6609e82448)
|
||||
|
||||
#### [v4.16.7](https://github.com/rive-app/rive-react/compare/v4.16.6...v4.16.7)
|
||||
|
||||
> 27 November 2024
|
||||
|
||||
- chore: release 4.16.7 [`1f6ae83`](https://github.com/rive-app/rive-react/commit/1f6ae83de319a244cb3fb84766cbcc10e2d7197b)
|
||||
- bump rive canvas to 2.23.11 [`e5ff233`](https://github.com/rive-app/rive-react/commit/e5ff233c34241d19f16cd1b5bb1ceaba1d36a43e)
|
||||
|
||||
#### [v4.16.6](https://github.com/rive-app/rive-react/compare/v4.16.5...v4.16.6)
|
||||
|
||||
> 22 November 2024
|
||||
|
||||
- chore: release 4.16.6 [`6479556`](https://github.com/rive-app/rive-react/commit/64795564d806df0f3bb8c8dfe865a5f7a41dfd2a)
|
||||
- Bump rive canvas to 2.23.10 [`f0b3205`](https://github.com/rive-app/rive-react/commit/f0b32056a4488aef59f9f6b17522c61ac7f483f6)
|
||||
|
||||
#### [v4.16.5](https://github.com/rive-app/rive-react/compare/v4.16.4...v4.16.5)
|
||||
|
||||
> 21 November 2024
|
||||
|
||||
- chore: release 4.16.5 [`b5dc2fa`](https://github.com/rive-app/rive-react/commit/b5dc2fa8dad4858322e1b0d626c6dd9ae949e2f9)
|
||||
- update rive canvas version [`0108d42`](https://github.com/rive-app/rive-react/commit/0108d425dd35603db9da1f1d99d0c00a5dcb86b0)
|
||||
|
||||
#### [v4.16.4](https://github.com/rive-app/rive-react/compare/v4.16.3...v4.16.4)
|
||||
|
||||
> 15 November 2024
|
||||
|
||||
- chore: release 4.16.4 [`74a2714`](https://github.com/rive-app/rive-react/commit/74a27143b41773436c3e7125e8047572b5cde009)
|
||||
- bump rive canvas to 2.23.8 [`2cfb8a4`](https://github.com/rive-app/rive-react/commit/2cfb8a4955b2bc18e1895680cfcd2b305005cce1)
|
||||
|
||||
#### [v4.16.3](https://github.com/rive-app/rive-react/compare/v4.16.2...v4.16.3)
|
||||
|
||||
> 14 November 2024
|
||||
|
||||
- chore: release 4.16.3 [`af6c3f8`](https://github.com/rive-app/rive-react/commit/af6c3f84c6dd4dc21731ca8457efe33a6ae1578c)
|
||||
- bump rive canvas to 2.23.7 [`351d996`](https://github.com/rive-app/rive-react/commit/351d9966b17180a1402d29ca71a1f5aef1d804ac)
|
||||
- update react to 2.23.6 [`ba73cb7`](https://github.com/rive-app/rive-react/commit/ba73cb7053a3ac729e24dc05d6e0ae272f84f12f)
|
||||
|
||||
#### [v4.16.2](https://github.com/rive-app/rive-react/compare/v4.16.1...v4.16.2)
|
||||
|
||||
> 12 November 2024
|
||||
|
||||
- chore: release 4.16.2 [`4a4f8a7`](https://github.com/rive-app/rive-react/commit/4a4f8a7151dd37a0925d72897716939e75f95395)
|
||||
- updated rive canvas [`b5baef5`](https://github.com/rive-app/rive-react/commit/b5baef5ce72741df8dd970e64ae22e3f8b8da795)
|
||||
|
||||
#### [v4.16.1](https://github.com/rive-app/rive-react/compare/v4.16.0...v4.16.1)
|
||||
|
||||
> 5 November 2024
|
||||
|
||||
- chore: release 4.16.1 [`79f80d3`](https://github.com/rive-app/rive-react/commit/79f80d39cd2d8f5d2fad691b765f5e27a31db9ba)
|
||||
- bump to canvas 2.23.4 [`e1ed825`](https://github.com/rive-app/rive-react/commit/e1ed8250e351f6efa19589111310021e09f7e70c)
|
||||
|
||||
#### [v4.16.0](https://github.com/rive-app/rive-react/compare/v4.15.2...v4.16.0)
|
||||
|
||||
> 1 November 2024
|
||||
|
||||
- chore: release 4.16.0 [`a40ba0d`](https://github.com/rive-app/rive-react/commit/a40ba0dacc9ac0535abaa4448f904a44067a3b10)
|
||||
- chore: bump js and use public setters [`99489af`](https://github.com/rive-app/rive-react/commit/99489af287e85122c9cbe75dc6b97b393254484e)
|
||||
- chore: bump again to make type check happy [`7ea9c8f`](https://github.com/rive-app/rive-react/commit/7ea9c8fbcbaeb3910ddcc88766e7a5a1061fa89d)
|
||||
|
||||
#### [v4.15.2](https://github.com/rive-app/rive-react/compare/v4.15.1...v4.15.2)
|
||||
|
||||
> 30 October 2024
|
||||
|
||||
- chore: release 4.15.2 [`2e461c6`](https://github.com/rive-app/rive-react/commit/2e461c66b37d29b05ce3a0d02547db933b7dd33f)
|
||||
- fix: account for scale factor in layout resizing [`bb07829`](https://github.com/rive-app/rive-react/commit/bb078296d0d694e5b6db0271bac52b207c5094ec)
|
||||
|
||||
#### [v4.15.1](https://github.com/rive-app/rive-react/compare/v4.15.0...v4.15.1)
|
||||
|
||||
> 30 October 2024
|
||||
|
||||
- chore: release 4.15.1 [`f9bad8b`](https://github.com/rive-app/rive-react/commit/f9bad8b62d3919fdbcfd6d5f62e77d8b920d5e8e)
|
||||
- fix: additional layout configuration that react needs [`83fa663`](https://github.com/rive-app/rive-react/commit/83fa6635ec5fc51e4651f0705fdb392f84d6421d)
|
||||
- fix: only perform layout resizing if the Layout object exists [`e42f5e3`](https://github.com/rive-app/rive-react/commit/e42f5e32d7968f26008d61248b74bb6c16d74647)
|
||||
|
||||
#### [v4.15.0](https://github.com/rive-app/rive-react/compare/v4.14.6...v4.15.0)
|
||||
|
||||
> 30 October 2024
|
||||
|
||||
- chore: release 4.15.0 [`bdd4c84`](https://github.com/rive-app/rive-react/commit/bdd4c84d8b32fafb775afcaded6c16ec158892bb)
|
||||
- feat: responsive layouts! [`414543d`](https://github.com/rive-app/rive-react/commit/414543d37dde248a7028d9d6a43c3c7dee3d49f6)
|
||||
|
||||
#### [v4.14.6](https://github.com/rive-app/rive-react/compare/v4.14.5...v4.14.6)
|
||||
|
||||
> 29 October 2024
|
||||
|
||||
- chore: release 4.14.6 [`119f7ee`](https://github.com/rive-app/rive-react/commit/119f7eea2a7b29e79dd837c36e5c0fb37232d554)
|
||||
- rive canvas 2.21.7 [`92b0342`](https://github.com/rive-app/rive-react/commit/92b0342882ff44eb55526a43804cae2499a4bea2)
|
||||
|
||||
#### [v4.14.5](https://github.com/rive-app/rive-react/compare/v4.14.4...v4.14.5)
|
||||
|
||||
> 15 October 2024
|
||||
|
||||
- chore: release 4.14.5 [`38b0a1c`](https://github.com/rive-app/rive-react/commit/38b0a1cc8638c0e1406c5cc7e3305875cb1f3c3a)
|
||||
- rive canvas 2.21.6 [`2fd87e4`](https://github.com/rive-app/rive-react/commit/2fd87e45e82a14da9576041fcdf3105187b81953)
|
||||
|
||||
#### [v4.14.4](https://github.com/rive-app/rive-react/compare/v4.14.3...v4.14.4)
|
||||
|
||||
> 2 October 2024
|
||||
|
||||
- chore: release 4.14.4 [`dc99fe2`](https://github.com/rive-app/rive-react/commit/dc99fe27ccdb5697db4374c7f7617bacb17e957d)
|
||||
- update rive to 2.21.5 [`2358c82`](https://github.com/rive-app/rive-react/commit/2358c826267c16e7f6d518b4c439c951c9c4ebc9)
|
||||
|
||||
#### [v4.14.3](https://github.com/rive-app/rive-react/compare/v4.14.2...v4.14.3)
|
||||
|
||||
> 1 October 2024
|
||||
|
||||
- chore: release 4.14.3 [`0475d47`](https://github.com/rive-app/rive-react/commit/0475d475356d88f9a6abc704de080b8087b1777e)
|
||||
- update rive to 2.21.4 [`f51e538`](https://github.com/rive-app/rive-react/commit/f51e53847900118c71a48cd38bd0cf69a1fea6a7)
|
||||
|
||||
#### [v4.14.2](https://github.com/rive-app/rive-react/compare/v4.14.1...v4.14.2)
|
||||
|
||||
> 23 September 2024
|
||||
|
||||
- chore: release 4.14.2 [`29fa6e7`](https://github.com/rive-app/rive-react/commit/29fa6e76fb149aedfe6e88db6f543e7ce1361199)
|
||||
- bump rive canvas to 2.21.3 [`2459c48`](https://github.com/rive-app/rive-react/commit/2459c489bf62a04ff62cacb61308677b1f0cc42f)
|
||||
|
||||
#### [v4.14.1](https://github.com/rive-app/rive-react/compare/v4.14.0...v4.14.1)
|
||||
|
||||
> 17 September 2024
|
||||
|
||||
- chore: release 4.14.1 [`927dbc6`](https://github.com/rive-app/rive-react/commit/927dbc6b32bfa4c7ceaf53acdb0c637db9f3a52c)
|
||||
- bump rive canvas to 2.21.1 [`8ebbfb1`](https://github.com/rive-app/rive-react/commit/8ebbfb164f0d5adfa7d45f0a5bb14af7f748c0f3)
|
||||
|
||||
#### [v4.14.0](https://github.com/rive-app/rive-react/compare/v4.13.10...v4.14.0)
|
||||
|
||||
> 13 September 2024
|
||||
|
||||
- chore: release 4.14.0 [`388fd16`](https://github.com/rive-app/rive-react/commit/388fd16b5b560ba5f8872bf40067acf531de6836)
|
||||
- chore: bump rive canvas to 2.21.0 [`8c87bc0`](https://github.com/rive-app/rive-react/commit/8c87bc0ab74d726445f2fd9a90b3f904fdc3d92d)
|
||||
|
||||
#### [v4.13.10](https://github.com/rive-app/rive-react/compare/v4.13.9...v4.13.10)
|
||||
|
||||
> 12 September 2024
|
||||
|
||||
- chore: release 4.13.10 [`280b2ec`](https://github.com/rive-app/rive-react/commit/280b2ec4a4a99e71aacfe1075d6be4914cc2f629)
|
||||
- bump rive canvas to 2.20.2 [`55a40c7`](https://github.com/rive-app/rive-react/commit/55a40c7d9f8cfc9fa1b14b1003deb65bdefd8f47)
|
||||
|
||||
#### [v4.13.9](https://github.com/rive-app/rive-react/compare/v4.13.8...v4.13.9)
|
||||
|
||||
> 10 September 2024
|
||||
|
||||
- chore: release 4.13.9 [`d4e6243`](https://github.com/rive-app/rive-react/commit/d4e6243dbbab6b0be0454bdc69e71e95610b1dbf)
|
||||
- docs: update links [`2ae22d6`](https://github.com/rive-app/rive-react/commit/2ae22d6c3021188c3e175ebc4a0bc8a02355db26)
|
||||
- bump react canvas [`dc738d0`](https://github.com/rive-app/rive-react/commit/dc738d00a6011c9bb25ce94e5a3fe50ac12764c2)
|
||||
|
||||
#### [v4.13.8](https://github.com/rive-app/rive-react/compare/v4.13.7...v4.13.8)
|
||||
|
||||
> 21 August 2024
|
||||
|
||||
- chore: release 4.13.8 [`4a3fc22`](https://github.com/rive-app/rive-react/commit/4a3fc222617b9baef46becbf1eb4ee4d6a15d4ab)
|
||||
- update rive canvas [`bdc734b`](https://github.com/rive-app/rive-react/commit/bdc734b90be82bcf4a78599ea2c63c15a6045dba)
|
||||
|
||||
#### [v4.13.7](https://github.com/rive-app/rive-react/compare/v4.13.6...v4.13.7)
|
||||
|
||||
> 15 August 2024
|
||||
|
||||
- chore: release 4.13.7 [`eeda717`](https://github.com/rive-app/rive-react/commit/eeda717178a9c7ccd2be39f8d3fcd0fd2f0ef3ea)
|
||||
- update rive canvas to 2.19.8 [`178f04d`](https://github.com/rive-app/rive-react/commit/178f04df611dee34781c74fb0de61d73c37c3720)
|
||||
|
||||
#### [v4.13.6](https://github.com/rive-app/rive-react/compare/v4.13.5...v4.13.6)
|
||||
|
||||
> 9 August 2024
|
||||
|
||||
- chore: release 4.13.6 [`ef11079`](https://github.com/rive-app/rive-react/commit/ef11079784b4f1b22574c04700dd9705257dbf38)
|
||||
- update rive canvas to 2.19.7 [`11f548b`](https://github.com/rive-app/rive-react/commit/11f548b21c0c462e2de111d50d70a54692af599d)
|
||||
|
||||
#### [v4.13.5](https://github.com/rive-app/rive-react/compare/v4.13.4...v4.13.5)
|
||||
|
||||
> 29 July 2024
|
||||
|
||||
- chore: release 4.13.5 [`d0ff23c`](https://github.com/rive-app/rive-react/commit/d0ff23c1243121a28ad8144d28860ba0a587a16a)
|
||||
- fix: add webgl2 package to dependencies [`a83f5a2`](https://github.com/rive-app/rive-react/commit/a83f5a275af8e05a48a027d78c059aec039ef4bd)
|
||||
|
||||
#### [v4.13.4](https://github.com/rive-app/rive-react/compare/v4.13.3...v4.13.4)
|
||||
|
||||
> 23 July 2024
|
||||
|
||||
- chore: release 4.13.4 [`b437230`](https://github.com/rive-app/rive-react/commit/b43723006331efb940c805cf3b4ca1b82047269f)
|
||||
- update rive version to 2.19.4 [`1091205`](https://github.com/rive-app/rive-react/commit/10912052f2bbcfec9830e8e23fa4bf7ddfa546cd)
|
||||
|
||||
#### [v4.13.3](https://github.com/rive-app/rive-react/compare/v4.13.2...v4.13.3)
|
||||
|
||||
> 10 July 2024
|
||||
|
||||
- chore: release 4.13.3 [`fe8265c`](https://github.com/rive-app/rive-react/commit/fe8265cd5809193c2b52b306666430e3f84c1dcc)
|
||||
- update rive version to 2.19.3 [`5b458b7`](https://github.com/rive-app/rive-react/commit/5b458b76e5c8ffa4383d3fe89e020f95154f87fe)
|
||||
|
||||
#### [v4.13.2](https://github.com/rive-app/rive-react/compare/v4.13.1...v4.13.2)
|
||||
|
||||
> 5 July 2024
|
||||
|
||||
- chore: release 4.13.2 [`1decbc7`](https://github.com/rive-app/rive-react/commit/1decbc7d85c5f225dc1def8fa09207f8db102632)
|
||||
- update rive version to 2.19.2 [`8762712`](https://github.com/rive-app/rive-react/commit/87627125f571f85a4cd71a8d7c48af1032d32747)
|
||||
|
||||
#### [v4.13.1](https://github.com/rive-app/rive-react/compare/v4.13.0...v4.13.1)
|
||||
|
||||
> 3 July 2024
|
||||
|
||||
- chore: release 4.13.1 [`e823e95`](https://github.com/rive-app/rive-react/commit/e823e9519f9ffa6bb3a1e4fd8bd3b2c98f6143a6)
|
||||
- update rive version to 2.19.1 [`ac88187`](https://github.com/rive-app/rive-react/commit/ac881871189a134b821a86e25029d2db056c2bef)
|
||||
- fix: change initialization from play to load event [`1897e82`](https://github.com/rive-app/rive-react/commit/1897e823b9bd500813c96a1512d90dc3b9bbe976)
|
||||
|
||||
#### [v4.13.0](https://github.com/rive-app/rive-react/compare/v4.12.1...v4.13.0)
|
||||
|
||||
> 28 June 2024
|
||||
|
||||
- chore: release 4.13.0 [`1a2e57a`](https://github.com/rive-app/rive-react/commit/1a2e57a82c391a602e72721945b93c43949ea23b)
|
||||
- update rive version to 2.19.0 [`0d16fee`](https://github.com/rive-app/rive-react/commit/0d16feeec196cb17fd44a875aa132c014aa44243)
|
||||
|
||||
#### [v4.12.1](https://github.com/rive-app/rive-react/compare/v4.12.0...v4.12.1)
|
||||
|
||||
> 25 June 2024
|
||||
|
||||
- fix: catch RiveFile initialization error in hook [`9b02c0f`](https://github.com/rive-app/rive-react/commit/9b02c0f1bc7fb61e17f5d6f51da120c11e82e61a)
|
||||
- chore: release 4.12.1 [`ca48907`](https://github.com/rive-app/rive-react/commit/ca48907649a8dae636947e95afb8931e2299e5c6)
|
||||
|
||||
#### [v4.12.0](https://github.com/rive-app/rive-react/compare/v4.11.3...v4.12.0)
|
||||
|
||||
> 18 June 2024
|
||||
|
||||
- chore: release 4.12.0 [`b25c775`](https://github.com/rive-app/rive-react/commit/b25c7759947b3eaa2b3e62e3304f269235128179)
|
||||
- chore: bump rive web to 2.18.0 [`17811ad`](https://github.com/rive-app/rive-react/commit/17811adac4976b01a797589342d74f42a0972cb8)
|
||||
|
||||
#### [v4.11.3](https://github.com/rive-app/rive-react/compare/v4.11.2...v4.11.3)
|
||||
|
||||
> 8 June 2024
|
||||
|
||||
- chore: release 4.11.3 [`e4fcef5`](https://github.com/rive-app/rive-react/commit/e4fcef529e84882004162355782f3b304e9260a8)
|
||||
- update rive canvas to 2.17.3 [`f51fe6e`](https://github.com/rive-app/rive-react/commit/f51fe6ee2aafef72f9272e49535d4f2c89b9b44f)
|
||||
|
||||
#### [v4.11.2](https://github.com/rive-app/rive-react/compare/v4.11.1...v4.11.2)
|
||||
|
||||
> 7 June 2024
|
||||
|
||||
- chore: release 4.11.2 [`0f558e6`](https://github.com/rive-app/rive-react/commit/0f558e66e1a78aae923bd79c39b25c9725eb76bd)
|
||||
- bump rive [`7a67fb1`](https://github.com/rive-app/rive-react/commit/7a67fb14f7cb581e2fa823e9d968fc506ce2834e)
|
||||
|
||||
#### [v4.11.1](https://github.com/rive-app/rive-react/compare/v4.11.0...v4.11.1)
|
||||
|
||||
> 6 June 2024
|
||||
|
||||
- chore: release 4.11.1 [`da3fc31`](https://github.com/rive-app/rive-react/commit/da3fc317ff9cc275a30d5a42adad3d0532947f9a)
|
||||
- chore: release 4.11.0 [`aa92c01`](https://github.com/rive-app/rive-react/commit/aa92c013296bfd4c848e1c41b0c52ad48b1f6ab7)
|
||||
- update rive version [`9b40a1a`](https://github.com/rive-app/rive-react/commit/9b40a1a02e1877445b3e3dc35b96a4b7e3a54780)
|
||||
|
||||
#### [v4.11.0](https://github.com/rive-app/rive-react/compare/v4.10.0...v4.11.0)
|
||||
|
||||
> 6 June 2024
|
||||
|
||||
- chore: release 4.11.0 [`2142210`](https://github.com/rive-app/rive-react/commit/21422104c9d502887352c40a6e185c69098f438d)
|
||||
- chore: bump web to v2.17.0 [`99a8a42`](https://github.com/rive-app/rive-react/commit/99a8a42a15969e70c96cc90460ec9fcba514ed4c)
|
||||
|
||||
#### [v4.10.0](https://github.com/rive-app/rive-react/compare/v4.9.5...v4.10.0)
|
||||
|
||||
> 28 May 2024
|
||||
|
||||
- fix observer and use single instance [`c324332`](https://github.com/rive-app/rive-react/commit/c32433284ad4116170ab016139ecba7678e6c21e)
|
||||
- feat: create useRiveFile hook [`16dc257`](https://github.com/rive-app/rive-react/commit/16dc257b2f904d51101535002b9fb34640a65842)
|
||||
- change hooks lifecycle to account for component reloading [`8e181d6`](https://github.com/rive-app/rive-react/commit/8e181d6ae2dff82875c60be789dcd63bedaba883)
|
||||
|
||||
#### [v4.9.5](https://github.com/rive-app/rive-react/compare/v4.9.4...v4.9.5)
|
||||
|
||||
> 10 May 2024
|
||||
|
||||
- chore: release 4.9.5 [`a3a41dc`](https://github.com/rive-app/rive-react/commit/a3a41dca404193a900f021a2358d85d4ab44fb26)
|
||||
- bump canvas to 2.15.6 [`b78c971`](https://github.com/rive-app/rive-react/commit/b78c9715d713031d0dbdacb8c4517be5d5a411b8)
|
||||
|
||||
#### [v4.9.4](https://github.com/rive-app/rive-react/compare/v4.9.3...v4.9.4)
|
||||
|
||||
> 9 May 2024
|
||||
|
||||
- chore: release 4.9.4 [`520e5bb`](https://github.com/rive-app/rive-react/commit/520e5bb51d8c31b769149a6daee2c84ec0a1a3d6)
|
||||
- bump version to 2.15.5 [`586ee4c`](https://github.com/rive-app/rive-react/commit/586ee4c002a13251d8f13adce11bc6f9cda3a904)
|
||||
|
||||
#### [v4.9.3](https://github.com/rive-app/rive-react/compare/v4.9.2...v4.9.3)
|
||||
|
||||
> 8 May 2024
|
||||
|
||||
- chore: release 4.9.3 [`3d6c7ed`](https://github.com/rive-app/rive-react/commit/3d6c7ed4991da4b729b11e02ea2cda3d3f6b078c)
|
||||
- bump version to 2.15.4 [`c3900b7`](https://github.com/rive-app/rive-react/commit/c3900b7845a63862b7da0d64d16294dd015e876e)
|
||||
|
||||
#### [v4.9.2](https://github.com/rive-app/rive-react/compare/v4.9.1...v4.9.2)
|
||||
|
||||
> 30 April 2024
|
||||
|
||||
- chore: release 4.9.2 [`d369817`](https://github.com/rive-app/rive-react/commit/d3698171138887e4a27180b31c40750090fb0863)
|
||||
- bump rive canvas to 2.15.2 [`d68302c`](https://github.com/rive-app/rive-react/commit/d68302ccb3f5756b753f29897033da2c0aa015d5)
|
||||
|
||||
#### [v4.9.1](https://github.com/rive-app/rive-react/compare/v4.9.0...v4.9.1)
|
||||
|
||||
> 30 April 2024
|
||||
|
||||
- chore: release 4.9.1 [`bbd4cc7`](https://github.com/rive-app/rive-react/commit/bbd4cc7af651df5fb5f28313b7e7e55e294a0282)
|
||||
- update to version 2.15.1 [`3936277`](https://github.com/rive-app/rive-react/commit/3936277f658981f6928bf0ef77ea01bb60ce27c5)
|
||||
|
||||
#### [v4.9.0](https://github.com/rive-app/rive-react/compare/v4.8.10...v4.9.0)
|
||||
|
||||
> 24 April 2024
|
||||
|
||||
- chore: release 4.9.0 [`aa2a783`](https://github.com/rive-app/rive-react/commit/aa2a783d1c5e6560f59fc8299858d68464a28308)
|
||||
- chore: bump rive wasm to v2.15.0 [`d8d7d64`](https://github.com/rive-app/rive-react/commit/d8d7d64749ff019edd6d50ea98dea9000967071a)
|
||||
|
||||
#### [v4.8.10](https://github.com/rive-app/rive-react/compare/v4.8.9...v4.8.10)
|
||||
|
||||
> 23 April 2024
|
||||
|
||||
- chore: release 4.8.10 [`af3edad`](https://github.com/rive-app/rive-react/commit/af3edad2c20e820569544318bd68bb3c56b9e180)
|
||||
- bump rive library dependencies to 2.14.4 [`5326f80`](https://github.com/rive-app/rive-react/commit/5326f800f7a99eafa9c2081e22966509f89008da)
|
||||
|
||||
#### [v4.8.9](https://github.com/rive-app/rive-react/compare/v4.8.8...v4.8.9)
|
||||
|
||||
> 18 April 2024
|
||||
|
||||
- chore: release 4.8.9 [`b44f9ad`](https://github.com/rive-app/rive-react/commit/b44f9ad9e157702af5b5a946c8a476f4842392ce)
|
||||
- Bump rive js libraries to 2.14.3 [`b249530`](https://github.com/rive-app/rive-react/commit/b2495300b7a7badcdfb6ced96c2eabb8779c36f0)
|
||||
|
||||
#### [v4.8.8](https://github.com/rive-app/rive-react/compare/v4.8.7...v4.8.8)
|
||||
|
||||
> 17 April 2024
|
||||
|
||||
- chore: release 4.8.8 [`eb43626`](https://github.com/rive-app/rive-react/commit/eb436263d786ffdee20d39dea0ce16b8aec101a9)
|
||||
- bump canvas and webgl to 2.14.2 [`0e63852`](https://github.com/rive-app/rive-react/commit/0e6385288ec85c40c5e7f4bc6f15b98a02ec6b88)
|
||||
|
||||
#### [v4.8.7](https://github.com/rive-app/rive-react/compare/v4.8.6...v4.8.7)
|
||||
|
||||
> 11 April 2024
|
||||
|
||||
- chore: release 4.8.7 [`78f7543`](https://github.com/rive-app/rive-react/commit/78f75434fc179326918f6e837058a74fa4a8dbd6)
|
||||
- bump react canvas to 2.14.1 [`a9c2950`](https://github.com/rive-app/rive-react/commit/a9c29504191d929b7e96587100d375ba6787deb2)
|
||||
|
||||
#### [v4.8.6](https://github.com/rive-app/rive-react/compare/v4.8.5...v4.8.6)
|
||||
|
||||
> 9 April 2024
|
||||
|
||||
- chore: release 4.8.6 [`e799f64`](https://github.com/rive-app/rive-react/commit/e799f64554e05de8c3b0666aa7091859576d37ba)
|
||||
- Bump rive-canvas to 2.13.2 [`95a1daa`](https://github.com/rive-app/rive-react/commit/95a1daa4efbb3835e886317ad16161fe8ac843a5)
|
||||
|
||||
#### [v4.8.5](https://github.com/rive-app/rive-react/compare/v4.8.4...v4.8.5)
|
||||
|
||||
> 8 April 2024
|
||||
|
||||
- chore: release 4.8.5 [`8a5b88c`](https://github.com/rive-app/rive-react/commit/8a5b88c59132e5d04fdcce1db903397fd15b5a18)
|
||||
- bump version to 2.13.0 [`d3b29cf`](https://github.com/rive-app/rive-react/commit/d3b29cf7d7c6fe99e4e12f4579ef0876ef875b35)
|
||||
|
||||
#### [v4.8.4](https://github.com/rive-app/rive-react/compare/v4.8.3...v4.8.4)
|
||||
|
||||
> 29 March 2024
|
||||
|
||||
- feat: add new webgl2 package for new Rive Renderer [`a7875b2`](https://github.com/rive-app/rive-react/commit/a7875b26a43342f6380a5009b25b831acfcfb610)
|
||||
- chore: release 4.8.4 [`611522b`](https://github.com/rive-app/rive-react/commit/611522b3e06c30923b4aefa737310c376dab861c)
|
||||
- Update README.md [`4653b8b`](https://github.com/rive-app/rive-react/commit/4653b8bea1169408c94962e80fe3f2c34c8b221f)
|
||||
- bump version to 2.12.0 [`89d3597`](https://github.com/rive-app/rive-react/commit/89d35976d4c8c91eddeb35b9dda5e3073ef45851)
|
||||
|
||||
#### [v4.8.3](https://github.com/rive-app/rive-react/compare/v4.8.2...v4.8.3)
|
||||
|
||||
|
||||
18
README.md
18
README.md
@@ -27,17 +27,25 @@ This library is a wrapper around the [JS/Wasm runtime](https://github.com/rive-a
|
||||
|
||||
:house_with_garden: [Homepage](https://rive.app/)
|
||||
|
||||
:blue_book: [General help docs](https://help.rive.app/)
|
||||
:blue_book: [General help docs](https://rive.app/community/doc/)
|
||||
|
||||
🛠 [Resources for building in Rive](https://rive.app/resources/)
|
||||
🛠 [Rive Forums](https://rive.app/community/forums/home)
|
||||
|
||||
## Getting started
|
||||
|
||||
Follow along with the link below for a quick start in getting Rive React integrated into your React apps.
|
||||
|
||||
[Getting Started with Rive in React](https://help.rive.app/runtimes/overview/react)
|
||||
- [Getting Started with Rive in React](https://rive.app/community/doc/react/docRfaSQ0eaE)
|
||||
- [API documentation](https://rive.app/community/doc/parameters-and-return-values/docJlDMNulDh)
|
||||
|
||||
[API documentation](https://help.rive.app/runtimes/overview/react/parameters-and-return-values)
|
||||
For more information, see the Runtime sections of the Rive help documentation:
|
||||
|
||||
- [Animation Playback](https://rive.app/community/doc/animation-playback/docDKKxsr7ko)
|
||||
- [Layout](https://rive.app/community/doc/layout/docBl81zd1GB)
|
||||
- [State Machines](https://rive.app/community/doc/state-machines/docxeznG7iiK)
|
||||
- [Rive Text](https://rive.app/community/doc/text/docn2E6y1lXo)
|
||||
- [Rive Events](https://rive.app/community/doc/rive-events/docbOnaeffgr)
|
||||
- [Loading Assets](https://rive.app/community/doc/loading-assets/doct4wVHGPgC)
|
||||
|
||||
## Supported versions
|
||||
|
||||
@@ -60,7 +68,7 @@ For even more examples and resources on using Rive at runtime or in other tools,
|
||||
|
||||
Using an older version of the runtime and need to learn how to upgrade to the latest version? Check out the migration guides below in our help center that help guide you through version bumps; breaking changes and all!
|
||||
|
||||
[Migration guides](https://help.rive.app/runtimes/overview/react/migrating-from-1.x.x-to-3.x.x)
|
||||
[Migration guides](https://rive.app/community/doc/migrating-from-v3-to-v4/dociIPXVHKFF)
|
||||
|
||||
## Contributing
|
||||
|
||||
|
||||
@@ -16,7 +16,7 @@ import './rive-overview.css';
|
||||
|
||||
# State Machine Usage
|
||||
|
||||
Not familiar with Rive State Machines? Check out our [help docs](https://help.rive.app/editor/state-machine) on what these are first!
|
||||
Not familiar with Rive State Machines? Check out our [help docs](https://rive.app/community/doc/state-machine/docwH5zPdh93) on what these are first!
|
||||
|
||||
The `useStateMachineInput` hook is a helper that makes grabbing references to state machine inputs easier to setup. This hook should be used along with the `useRive` hook, as you need to pass in the `rive` instance returned from `useRive`. See each of the examples below to see usage of the hook creating instance of three types of inputs:
|
||||
|
||||
|
||||
@@ -6,4 +6,4 @@ Output for `rive-react` using the backing `@rive-app/canvas-lite` JS runtime.
|
||||
|
||||
The current `@rive-app/react-canvas` dependency supports all Rive features and contains the necessary backing dependencies to render those graphics. This `lite` version has the same API, but does not compile and build with certain dependencies in order to keep the package size as small as possible.
|
||||
|
||||
At this time, this lite version of `@rive-app/react-canvas-lite` will not render [Rive Text](https://help.rive.app/editor/text) onto the canvas. Note however, that even if your Rive file may include Rive Text components when using this package, the canvas will still render the graphic without the Rive Text components.
|
||||
At this time, this lite version of `@rive-app/react-canvas-lite` will not render Rive Text onto the canvas or play Rive Audio. Note however, that even if your Rive file may include Rive Text components, rendering the graphic should not cause any app errors, or cease to render. The same is true for playing audio.
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@rive-app/react-canvas-lite",
|
||||
"version": "4.8.4",
|
||||
"version": "4.17.8",
|
||||
"description": "React wrapper around the @rive-app/canvas-lite library",
|
||||
"main": "dist/index.js",
|
||||
"typings": "dist/types/index.d.ts",
|
||||
@@ -18,7 +18,7 @@
|
||||
},
|
||||
"homepage": "https://github.com/rive-app/rive-react#readme",
|
||||
"dependencies": {
|
||||
"@rive-app/canvas-lite": "2.12.0"
|
||||
"@rive-app/canvas-lite": "2.25.6"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"react": "^16.8.0 || ^17.0.0 || ^18.0.0"
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@rive-app/react-canvas",
|
||||
"version": "4.8.4",
|
||||
"version": "4.17.8",
|
||||
"description": "React wrapper around the @rive-app/canvas library",
|
||||
"main": "dist/index.js",
|
||||
"typings": "dist/types/index.d.ts",
|
||||
@@ -18,7 +18,7 @@
|
||||
},
|
||||
"homepage": "https://github.com/rive-app/rive-react#readme",
|
||||
"dependencies": {
|
||||
"@rive-app/canvas": "2.12.0"
|
||||
"@rive-app/canvas": "2.25.6"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"react": "^16.8.0 || ^17.0.0 || ^18.0.0"
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@rive-app/react-webgl",
|
||||
"version": "4.8.4",
|
||||
"version": "4.17.8",
|
||||
"description": "React wrapper around the @rive-app/webgl library",
|
||||
"main": "dist/index.js",
|
||||
"typings": "dist/types/index.d.ts",
|
||||
@@ -18,7 +18,7 @@
|
||||
},
|
||||
"homepage": "https://github.com/rive-app/rive-react#readme",
|
||||
"dependencies": {
|
||||
"@rive-app/webgl": "2.12.0"
|
||||
"@rive-app/webgl": "2.25.6"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"react": "^16.8.0 || ^17.0.0 || ^18.0.0"
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@rive-app/react-webgl2",
|
||||
"version": "4.8.4",
|
||||
"version": "4.17.8",
|
||||
"description": "React wrapper around the @rive-app/webgl2 library",
|
||||
"main": "dist/index.js",
|
||||
"typings": "dist/types/index.d.ts",
|
||||
@@ -17,7 +17,9 @@
|
||||
"url": "https://github.com/rive-app/rive-react/issues"
|
||||
},
|
||||
"homepage": "https://github.com/rive-app/rive-react#readme",
|
||||
"dependencies": {},
|
||||
"dependencies": {
|
||||
"@rive-app/webgl2": "2.25.6"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"react": "^16.8.0 || ^17.0.0 || ^18.0.0"
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "rive-react",
|
||||
"version": "4.8.4",
|
||||
"version": "4.17.8",
|
||||
"description": "React wrapper around the rive-js library",
|
||||
"main": "dist/index.js",
|
||||
"typings": "dist/types/index.d.ts",
|
||||
@@ -36,9 +36,10 @@
|
||||
},
|
||||
"homepage": "https://github.com/rive-app/rive-react#readme",
|
||||
"dependencies": {
|
||||
"@rive-app/canvas": "2.12.0",
|
||||
"@rive-app/canvas-lite": "2.12.0",
|
||||
"@rive-app/webgl": "2.12.0"
|
||||
"@rive-app/canvas": "2.25.6",
|
||||
"@rive-app/canvas-lite": "2.25.6",
|
||||
"@rive-app/webgl": "2.25.6",
|
||||
"@rive-app/webgl2": "2.25.6"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"react": "^16.8.0 || ^17.0.0 || ^18.0.0"
|
||||
|
||||
@@ -21,7 +21,7 @@ export interface RiveProps {
|
||||
*/
|
||||
stateMachines?: string | string[];
|
||||
/**
|
||||
* Specify a starting Layout object to set Fill and Alignment for the drawing surface. See docs at https://help.rive.app/runtimes/layout for more on layout configuration.
|
||||
* Specify a starting Layout object to set Fill and Alignment for the drawing surface. See docs at https://rive.app/community/doc/layout/docBl81zd1GB for more on layout configuration.
|
||||
*/
|
||||
layout?: Layout;
|
||||
/**
|
||||
|
||||
38
src/hooks/elementObserver.ts
Normal file
38
src/hooks/elementObserver.ts
Normal file
@@ -0,0 +1,38 @@
|
||||
class FakeIntersectionObserver {
|
||||
observe() {}
|
||||
unobserve() {}
|
||||
disconnect() {}
|
||||
}
|
||||
|
||||
const MyIntersectionObserver =
|
||||
globalThis.IntersectionObserver || FakeIntersectionObserver;
|
||||
|
||||
class ElementObserver {
|
||||
private observer;
|
||||
|
||||
private elementsMap: Map<Element, Function> = new Map();
|
||||
|
||||
constructor() {
|
||||
this.observer = new MyIntersectionObserver(this.onObserved);
|
||||
}
|
||||
public onObserved = (entries: IntersectionObserverEntry[]) => {
|
||||
entries.forEach((entry) => {
|
||||
const elementCallback = this.elementsMap.get(entry.target as Element);
|
||||
if (elementCallback) {
|
||||
elementCallback(entry);
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
public registerCallback(element: Element, callback: Function) {
|
||||
this.observer.observe(element);
|
||||
this.elementsMap.set(element, callback);
|
||||
}
|
||||
|
||||
public removeCallback(element: Element) {
|
||||
this.observer.unobserve(element);
|
||||
this.elementsMap.delete(element);
|
||||
}
|
||||
}
|
||||
|
||||
export default ElementObserver;
|
||||
32
src/hooks/useIntersectionObserver.ts
Normal file
32
src/hooks/useIntersectionObserver.ts
Normal file
@@ -0,0 +1,32 @@
|
||||
import { useCallback } from 'react';
|
||||
import ElementObserver from './elementObserver';
|
||||
|
||||
let observer: ElementObserver;
|
||||
const getObserver = () => {
|
||||
if(!observer) {
|
||||
observer = new ElementObserver();
|
||||
}
|
||||
return observer;
|
||||
}
|
||||
|
||||
/**
|
||||
* Hook to observe elements when they are intersecting with the viewport
|
||||
*
|
||||
* @returns - API to observer and unobserve elements
|
||||
*/
|
||||
export default function useIntersectionObserver() {
|
||||
const observe = useCallback((element: Element, callback: Function) => {
|
||||
const observer = getObserver();
|
||||
observer.registerCallback(element, callback);
|
||||
}, []);
|
||||
|
||||
const unobserve = useCallback((element: Element) => {
|
||||
const observer = getObserver();
|
||||
observer.removeCallback(element);
|
||||
}, []);
|
||||
|
||||
return {
|
||||
observe,
|
||||
unobserve,
|
||||
};
|
||||
}
|
||||
@@ -13,7 +13,7 @@ interface UseResizeCanvasProps {
|
||||
/**
|
||||
* Ref to the canvas element
|
||||
*/
|
||||
canvasRef: MutableRefObject<HTMLCanvasElement | null>;
|
||||
canvasElem: HTMLCanvasElement | null;
|
||||
/**
|
||||
* Ref to the container element of the canvas
|
||||
*/
|
||||
@@ -55,7 +55,7 @@ interface UseResizeCanvasProps {
|
||||
*/
|
||||
export default function useResizeCanvas({
|
||||
riveLoaded = false,
|
||||
canvasRef,
|
||||
canvasElem,
|
||||
containerRef,
|
||||
options = {},
|
||||
onCanvasHasResized,
|
||||
@@ -120,7 +120,7 @@ export default function useResizeCanvas({
|
||||
|
||||
const { width, height } = getContainerDimensions();
|
||||
let hasResized = false;
|
||||
if (canvasRef.current) {
|
||||
if (canvasElem) {
|
||||
// Check if the canvas parent container bounds have changed and set
|
||||
// new values accordingly
|
||||
const boundsChanged =
|
||||
@@ -138,10 +138,10 @@ export default function useResizeCanvas({
|
||||
if (boundsChanged || canvasSizeChanged) {
|
||||
const newCanvasWidthProp = currentDevicePixelRatio * width;
|
||||
const newCanvasHeightProp = currentDevicePixelRatio * height;
|
||||
canvasRef.current.width = newCanvasWidthProp;
|
||||
canvasRef.current.height = newCanvasHeightProp;
|
||||
canvasRef.current.style.width = width + 'px';
|
||||
canvasRef.current.style.height = height + 'px';
|
||||
canvasElem.width = newCanvasWidthProp;
|
||||
canvasElem.height = newCanvasHeightProp;
|
||||
canvasElem.style.width = width + 'px';
|
||||
canvasElem.style.height = height + 'px';
|
||||
setLastCanvasSize({
|
||||
width: newCanvasWidthProp,
|
||||
height: newCanvasHeightProp,
|
||||
@@ -149,8 +149,8 @@ export default function useResizeCanvas({
|
||||
hasResized = true;
|
||||
}
|
||||
} else if (boundsChanged) {
|
||||
canvasRef.current.width = width;
|
||||
canvasRef.current.height = height;
|
||||
canvasElem.width = width;
|
||||
canvasElem.height = height;
|
||||
setLastCanvasSize({
|
||||
width: width,
|
||||
height: height,
|
||||
@@ -167,7 +167,7 @@ export default function useResizeCanvas({
|
||||
}
|
||||
isFirstSizing && setIsFirstSizing(false);
|
||||
}, [
|
||||
canvasRef,
|
||||
canvasElem,
|
||||
containerRef,
|
||||
containerSize,
|
||||
currentDevicePixelRatio,
|
||||
@@ -184,4 +184,12 @@ export default function useResizeCanvas({
|
||||
shouldUseDevicePixelRatio,
|
||||
riveLoaded,
|
||||
]);
|
||||
|
||||
// Reset width and height values when the canvas changes
|
||||
useEffect(() => {
|
||||
setLastCanvasSize({
|
||||
width: 0,
|
||||
height: 0,
|
||||
});
|
||||
}, [canvasElem]);
|
||||
}
|
||||
|
||||
@@ -6,10 +6,12 @@ import React, {
|
||||
ComponentProps,
|
||||
RefCallback,
|
||||
} from 'react';
|
||||
import { Rive, EventType } from '@rive-app/canvas';
|
||||
import { Rive, EventType, Fit } from '@rive-app/canvas';
|
||||
import { UseRiveParameters, UseRiveOptions, RiveState } from '../types';
|
||||
import useResizeCanvas from './useResizeCanvas';
|
||||
import useDevicePixelRatio from './useDevicePixelRatio';
|
||||
import { getOptions } from '../utils';
|
||||
import useIntersectionObserver from './useIntersectionObserver';
|
||||
|
||||
type RiveComponentProps = {
|
||||
setContainerRef: RefCallback<HTMLElement>;
|
||||
@@ -65,7 +67,7 @@ export default function useRive(
|
||||
riveParams?: UseRiveParameters,
|
||||
opts: Partial<UseRiveOptions> = {}
|
||||
): RiveState {
|
||||
const canvasRef = useRef<HTMLCanvasElement | null>(null);
|
||||
const [canvasElem, setCanvasElem] = useState<HTMLCanvasElement | null>(null);
|
||||
const containerRef = useRef<HTMLElement | null>(null);
|
||||
|
||||
const [rive, setRive] = useState<Rive | null>(null);
|
||||
@@ -73,21 +75,32 @@ export default function useRive(
|
||||
const isParamsLoaded = Boolean(riveParams);
|
||||
const options = getOptions(opts);
|
||||
|
||||
const devicePixelRatio = useDevicePixelRatio();
|
||||
|
||||
/**
|
||||
* When the canvas/parent container resize, reset the Rive layout to match the
|
||||
* new (0, 0, canvas.width, canvas.height) bounds in the render loop
|
||||
*/
|
||||
const onCanvasHasResized = useCallback(() => {
|
||||
if (rive) {
|
||||
if (rive.layout && rive.layout.fit === Fit.Layout) {
|
||||
if (canvasElem) {
|
||||
const resizeFactor = devicePixelRatio * rive.layout.layoutScaleFactor;
|
||||
rive.devicePixelRatioUsed = devicePixelRatio;
|
||||
rive.artboardWidth = canvasElem?.width / resizeFactor;
|
||||
rive.artboardHeight = canvasElem?.height / resizeFactor;
|
||||
}
|
||||
}
|
||||
|
||||
rive.startRendering();
|
||||
rive.resizeToCanvas();
|
||||
}
|
||||
}, [rive]);
|
||||
}, [rive, devicePixelRatio]);
|
||||
|
||||
// Watch the canvas parent container resize and size the canvas to match
|
||||
useResizeCanvas({
|
||||
riveLoaded: !!rive,
|
||||
canvasRef,
|
||||
canvasElem,
|
||||
containerRef,
|
||||
options,
|
||||
onCanvasHasResized,
|
||||
@@ -99,32 +112,39 @@ export default function useRive(
|
||||
*/
|
||||
const setCanvasRef: RefCallback<HTMLCanvasElement> = useCallback(
|
||||
(canvas: HTMLCanvasElement | null) => {
|
||||
if (canvas && riveParams && isParamsLoaded) {
|
||||
const { useOffscreenRenderer } = options;
|
||||
const r = new Rive({
|
||||
useOffscreenRenderer,
|
||||
...riveParams,
|
||||
canvas,
|
||||
});
|
||||
r.on(EventType.Load, () => {
|
||||
// Check if the component/canvas is mounted before setting state to avoid setState
|
||||
// on an unmounted component in some rare cases
|
||||
if (canvasRef.current) {
|
||||
setRive(r);
|
||||
} else {
|
||||
// If unmounted, cleanup the rive object immediately
|
||||
r.cleanup();
|
||||
}
|
||||
});
|
||||
} else if (canvas === null && canvasRef.current) {
|
||||
canvasRef.current.height = 0;
|
||||
canvasRef.current.width = 0;
|
||||
if (canvas === null && canvasElem) {
|
||||
canvasElem.height = 0;
|
||||
canvasElem.width = 0;
|
||||
}
|
||||
|
||||
canvasRef.current = canvas;
|
||||
setCanvasElem(canvas);
|
||||
},
|
||||
[isParamsLoaded]
|
||||
[]
|
||||
);
|
||||
|
||||
useEffect(() => {
|
||||
if (!canvasElem || !riveParams) {
|
||||
return;
|
||||
}
|
||||
if (rive == null) {
|
||||
const { useOffscreenRenderer } = options;
|
||||
const r = new Rive({
|
||||
useOffscreenRenderer,
|
||||
...riveParams,
|
||||
canvas: canvasElem,
|
||||
});
|
||||
r.on(EventType.Load, () => {
|
||||
// Check if the component/canvas is mounted before setting state to avoid setState
|
||||
// on an unmounted component in some rare cases
|
||||
if (canvasElem) {
|
||||
setRive(r);
|
||||
} else {
|
||||
// If unmounted, cleanup the rive object immediately
|
||||
r.cleanup();
|
||||
}
|
||||
});
|
||||
}
|
||||
}, [canvasElem, isParamsLoaded, rive]);
|
||||
/**
|
||||
* Ref callback called when the container element mounts
|
||||
*/
|
||||
@@ -139,21 +159,62 @@ export default function useRive(
|
||||
* Set up IntersectionObserver to stop rendering if the animation is not in
|
||||
* view.
|
||||
*/
|
||||
const { observe, unobserve } = useIntersectionObserver();
|
||||
|
||||
useEffect(() => {
|
||||
const observer = new IntersectionObserver(([entry]) => {
|
||||
let timeoutId: ReturnType<typeof setTimeout>;
|
||||
let isPaused = false;
|
||||
// This is a workaround to retest whether an element is offscreen or not.
|
||||
// There seems to be a bug in Chrome that triggers an intersection change when an element
|
||||
// is moved within the DOM using insertBefore.
|
||||
// For some reason, when this is called whithin the context of a React application, the
|
||||
// intersection callback is called only once reporting isIntersecting as false but never
|
||||
// triggered back with isIntersecting as true.
|
||||
// For this reason we retest after 10 millisecond whether the element is actually off the
|
||||
// viewport or not.
|
||||
const retestIntersection = () => {
|
||||
if (canvasElem && isPaused) {
|
||||
const size = canvasElem.getBoundingClientRect();
|
||||
const isIntersecting =
|
||||
size.width > 0 &&
|
||||
size.height > 0 &&
|
||||
size.top <
|
||||
(window.innerHeight || document.documentElement.clientHeight) &&
|
||||
size.bottom > 0 &&
|
||||
size.left <
|
||||
(window.innerWidth || document.documentElement.clientWidth) &&
|
||||
size.right > 0;
|
||||
if (isIntersecting) {
|
||||
rive?.startRendering();
|
||||
isPaused = false;
|
||||
}
|
||||
}
|
||||
};
|
||||
const onChange = (entry: IntersectionObserverEntry) => {
|
||||
entry.isIntersecting
|
||||
? rive && rive.startRendering()
|
||||
: rive && rive.stopRendering();
|
||||
});
|
||||
|
||||
if (canvasRef.current) {
|
||||
observer.observe(canvasRef.current);
|
||||
}
|
||||
|
||||
return () => {
|
||||
observer.disconnect();
|
||||
isPaused = !entry.isIntersecting;
|
||||
clearTimeout(timeoutId);
|
||||
if (!entry.isIntersecting && entry.boundingClientRect.width === 0) {
|
||||
timeoutId = setTimeout(retestIntersection, 10);
|
||||
}
|
||||
};
|
||||
}, [rive]);
|
||||
if (canvasElem && options.shouldUseIntersectionObserver !== false) {
|
||||
observe(canvasElem, onChange);
|
||||
}
|
||||
return () => {
|
||||
if (canvasElem) {
|
||||
unobserve(canvasElem);
|
||||
}
|
||||
};
|
||||
}, [
|
||||
observe,
|
||||
unobserve,
|
||||
rive,
|
||||
canvasElem,
|
||||
options.shouldUseIntersectionObserver,
|
||||
]);
|
||||
|
||||
/**
|
||||
* On unmount, call cleanup to cleanup any WASM generated objects that need
|
||||
@@ -166,7 +227,7 @@ export default function useRive(
|
||||
setRive(null);
|
||||
}
|
||||
};
|
||||
}, [rive]);
|
||||
}, [rive, canvasElem]);
|
||||
|
||||
/**
|
||||
* Listen for changes in the animations params
|
||||
@@ -198,7 +259,7 @@ export default function useRive(
|
||||
);
|
||||
|
||||
return {
|
||||
canvas: canvasRef.current,
|
||||
canvas: canvasElem,
|
||||
container: containerRef.current,
|
||||
setCanvasRef,
|
||||
setContainerRef,
|
||||
|
||||
57
src/hooks/useRiveFile.ts
Normal file
57
src/hooks/useRiveFile.ts
Normal file
@@ -0,0 +1,57 @@
|
||||
import { useState, useEffect } from 'react';
|
||||
import type {
|
||||
UseRiveFileParameters,
|
||||
RiveFileState,
|
||||
FileStatus,
|
||||
} from '../types';
|
||||
import { EventType, RiveFile } from '@rive-app/canvas';
|
||||
|
||||
/**
|
||||
* Custom hook for initializing and managing a RiveFile instance within a component.
|
||||
* It sets up a RiveFile based on provided source parameters (URL or ArrayBuffer) and ensures
|
||||
* proper cleanup to avoid memory leaks when the component unmounts or inputs change.
|
||||
*
|
||||
* @param params - Object containing parameters accepted by the Rive file in the @rive-app/canvas runtime,
|
||||
*
|
||||
* @returns {RiveFileState} Contains the active RiveFile instance (`riveFile`) and the loading status.
|
||||
*/
|
||||
function useRiveFile(params: UseRiveFileParameters): RiveFileState {
|
||||
const [riveFile, setRiveFile] = useState<RiveFile | null>(null);
|
||||
const [status, setStatus] = useState<FileStatus>('idle');
|
||||
|
||||
useEffect(() => {
|
||||
let file: RiveFile | null = null;
|
||||
|
||||
const loadRiveFile = async () => {
|
||||
try {
|
||||
setStatus('loading');
|
||||
file = new RiveFile(params);
|
||||
file.init();
|
||||
file.on(EventType.Load, () => {
|
||||
// We request an instance to add +1 to the referencesCount so it doesn't get destroyed
|
||||
// while this hook is active
|
||||
file?.getInstance();
|
||||
setRiveFile(file);
|
||||
setStatus('success');
|
||||
});
|
||||
file.on(EventType.LoadError, () => {
|
||||
setStatus('failed');
|
||||
});
|
||||
setRiveFile(file);
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
setStatus('failed');
|
||||
}
|
||||
};
|
||||
|
||||
loadRiveFile();
|
||||
|
||||
return () => {
|
||||
file?.cleanup();
|
||||
};
|
||||
}, [params.src, params.buffer]);
|
||||
|
||||
return { riveFile, status };
|
||||
}
|
||||
|
||||
export default useRiveFile;
|
||||
@@ -40,7 +40,7 @@ export default function useStateMachineInput(
|
||||
}
|
||||
setStateMachineInput();
|
||||
if (rive) {
|
||||
rive.on(EventType.Play, () => {
|
||||
rive.on(EventType.Load, () => {
|
||||
// Check if the component/canvas is mounted before setting state to avoid setState
|
||||
// on an unmounted component in some rare cases
|
||||
setStateMachineInput();
|
||||
|
||||
@@ -2,8 +2,9 @@ import Rive, { RiveProps } from './components/Rive';
|
||||
import useRive from './hooks/useRive';
|
||||
import useStateMachineInput from './hooks/useStateMachineInput';
|
||||
import useResizeCanvas from './hooks/useResizeCanvas';
|
||||
import useRiveFile from './hooks/useRiveFile';
|
||||
|
||||
export default Rive;
|
||||
export { useRive, useStateMachineInput, useResizeCanvas, RiveProps };
|
||||
export { RiveState, UseRiveParameters, UseRiveOptions } from './types';
|
||||
export { useRive, useStateMachineInput, useResizeCanvas, useRiveFile , RiveProps };
|
||||
export { RiveState, UseRiveParameters, UseRiveFileParameters, UseRiveOptions } from './types';
|
||||
export * from '@rive-app/canvas';
|
||||
|
||||
32
src/types.ts
32
src/types.ts
@@ -1,5 +1,10 @@
|
||||
import { RefCallback, ComponentProps } from 'react';
|
||||
import { Rive, RiveParameters } from '@rive-app/canvas';
|
||||
import {
|
||||
Rive,
|
||||
RiveFile,
|
||||
RiveFileParameters,
|
||||
RiveParameters,
|
||||
} from '@rive-app/canvas';
|
||||
import { ComponentProps, RefCallback } from 'react';
|
||||
|
||||
export type UseRiveParameters = Partial<Omit<RiveParameters, 'canvas'>> | null;
|
||||
|
||||
@@ -9,6 +14,7 @@ export type UseRiveOptions = {
|
||||
fitCanvasToArtboardHeight: boolean;
|
||||
useOffscreenRenderer: boolean;
|
||||
shouldResizeCanvasToContainer: boolean;
|
||||
shouldUseIntersectionObserver?: boolean;
|
||||
};
|
||||
|
||||
export type Dimensions = {
|
||||
@@ -21,9 +27,9 @@ export type Dimensions = {
|
||||
* @property canvas - Canvas element the Rive Animation is attached to.
|
||||
* @property container - Container element of the canvas.
|
||||
* @property setCanvasRef - Ref callback to be passed to the canvas element.
|
||||
* @property setContainerRef - Ref callback to be passed to the container element
|
||||
* of the canvas. This is optional, however if not used then the hook will
|
||||
* not take care of automatically resizing the canvas to it's outer
|
||||
* @property setContainerRef - Ref callback to be passed to the container
|
||||
* element of the canvas. This is optional, however if not used then the hook
|
||||
* will not take care of automatically resizing the canvas to it's outer
|
||||
* container if the window resizes.
|
||||
* @property rive - The loaded Rive Animation
|
||||
*/
|
||||
@@ -35,3 +41,19 @@ export type RiveState = {
|
||||
rive: Rive | null;
|
||||
RiveComponent: (props: ComponentProps<'canvas'>) => JSX.Element;
|
||||
};
|
||||
|
||||
export type UseRiveFileParameters = Partial<
|
||||
Omit<RiveFileParameters, 'onLoad' | 'onLoadError'>
|
||||
>;
|
||||
|
||||
export type FileStatus = 'idle' | 'loading' | 'failed' | 'success';
|
||||
|
||||
/**
|
||||
* @typedef RiveFileState
|
||||
* @property data - The RiveFile instance
|
||||
* @property status - The status of the file
|
||||
*/
|
||||
export type RiveFileState = {
|
||||
riveFile: RiveFile | null;
|
||||
status: FileStatus;
|
||||
};
|
||||
|
||||
39
test/elementObserver.test.tsx
Normal file
39
test/elementObserver.test.tsx
Normal file
@@ -0,0 +1,39 @@
|
||||
// TODO move this
|
||||
const observe = jest.fn();
|
||||
const unobserve = jest.fn();
|
||||
const disconnect = jest.fn();
|
||||
|
||||
jest.spyOn(globalThis, 'IntersectionObserver').mockImplementation(() => {
|
||||
return {
|
||||
observe,
|
||||
unobserve,
|
||||
disconnect,
|
||||
root: null,
|
||||
thresholds: [],
|
||||
rootMargin: '',
|
||||
takeRecords: () => [],
|
||||
};
|
||||
});
|
||||
|
||||
import ElementObserver from '../src/hooks/elementObserver';
|
||||
|
||||
describe('elementObserver', () => {
|
||||
it('registers a callback and observes the element', () => {
|
||||
const observer = new ElementObserver();
|
||||
const element = document.createElement('li');
|
||||
observer.registerCallback(element, ()=>{});
|
||||
expect(observe).toHaveBeenCalled();
|
||||
expect(observe).toHaveBeenCalledWith(element);
|
||||
});
|
||||
|
||||
it('unregisters a callback and unobserves the element', () => {
|
||||
const observer = new ElementObserver();
|
||||
const element = document.createElement('li');
|
||||
observer.removeCallback(element);
|
||||
expect(unobserve).toHaveBeenCalled();
|
||||
expect(unobserve).toHaveBeenCalledWith(element);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
jest.clearAllMocks();
|
||||
42
test/useIntersectionObserver.test.tsx
Normal file
42
test/useIntersectionObserver.test.tsx
Normal file
@@ -0,0 +1,42 @@
|
||||
import { renderHook, act } from '@testing-library/react-hooks';
|
||||
import ElementObserver from '../src/hooks/elementObserver';
|
||||
jest.mock('../src/hooks/elementObserver');
|
||||
|
||||
import useIntersectionObserver from '../src/hooks/useIntersectionObserver';
|
||||
|
||||
describe('useIntersectionObserver', () => {
|
||||
it('returns an object on initialization', () => {
|
||||
const { result } = renderHook(() => useIntersectionObserver());
|
||||
expect(result.current).toBeDefined();
|
||||
});
|
||||
|
||||
it('registers a callback', () => {
|
||||
const { result } = renderHook(() => useIntersectionObserver());
|
||||
const element = document.createElement('li');
|
||||
const callback = () => {};
|
||||
act(() => {
|
||||
result.current.observe(element, callback);
|
||||
});
|
||||
const mockElementObserver = (ElementObserver as jest.Mock).mock
|
||||
.instances[0];
|
||||
const registerCallback = mockElementObserver.registerCallback;
|
||||
expect(registerCallback.mock.calls.length).toBe(1);
|
||||
expect(registerCallback.mock.calls[0].length).toBe(2);
|
||||
expect(registerCallback.mock.calls[0][0]).toBe(element);
|
||||
expect(registerCallback.mock.calls[0][1]).toBe(callback);
|
||||
});
|
||||
|
||||
it('unregisters a callback', () => {
|
||||
const { result } = renderHook(() => useIntersectionObserver());
|
||||
const element = document.createElement('li');
|
||||
act(() => {
|
||||
result.current.unobserve(element);
|
||||
});
|
||||
const mockElementObserver = (ElementObserver as jest.Mock).mock
|
||||
.instances[0];
|
||||
const removeCallback = mockElementObserver.removeCallback;
|
||||
expect(removeCallback.mock.calls.length).toBe(1);
|
||||
expect(removeCallback.mock.calls[0].length).toBe(1);
|
||||
expect(removeCallback.mock.calls[0][0]).toBe(element);
|
||||
});
|
||||
});
|
||||
@@ -4,7 +4,7 @@ import { renderHook, act } from '@testing-library/react-hooks';
|
||||
|
||||
import useRive from '../src/hooks/useRive';
|
||||
import * as rive from '@rive-app/canvas';
|
||||
import { render } from '@testing-library/react';
|
||||
import { render, waitFor } from '@testing-library/react';
|
||||
|
||||
jest.mock('@rive-app/canvas', () => ({
|
||||
Rive: jest.fn().mockImplementation(() => ({
|
||||
@@ -65,6 +65,11 @@ describe('useRive', () => {
|
||||
|
||||
await act(async () => {
|
||||
result.current.setCanvasRef(canvasSpy);
|
||||
});
|
||||
await waitFor(() => {
|
||||
expect(result.current.canvas).toBe(canvasSpy);
|
||||
});
|
||||
await act(async () => {
|
||||
controlledRiveloadCb();
|
||||
});
|
||||
expect(result.current.rive).toBe(baseRiveMock);
|
||||
@@ -93,7 +98,14 @@ describe('useRive', () => {
|
||||
await act(async () => {
|
||||
result.current.setCanvasRef(canvasSpy);
|
||||
result.current.setContainerRef(containerSpy);
|
||||
});
|
||||
await waitFor(() => {
|
||||
expect(result.current.canvas).toBe(canvasSpy);
|
||||
});
|
||||
await act(async () => {
|
||||
controlledRiveloadCb();
|
||||
});
|
||||
await act(async () => {
|
||||
jest.spyOn(containerSpy, 'clientWidth', 'get').mockReturnValue(500);
|
||||
jest.spyOn(containerSpy, 'clientHeight', 'get').mockReturnValue(500);
|
||||
containerSpy.dispatchEvent(new Event('resize'));
|
||||
@@ -125,6 +137,11 @@ describe('useRive', () => {
|
||||
|
||||
await act(async () => {
|
||||
result.current.setCanvasRef(canvasSpy);
|
||||
});
|
||||
await waitFor(() => {
|
||||
expect(result.current.canvas).toBe(canvasSpy);
|
||||
});
|
||||
await act(async () => {
|
||||
controlledRiveloadCb();
|
||||
});
|
||||
|
||||
@@ -153,6 +170,11 @@ describe('useRive', () => {
|
||||
await act(async () => {
|
||||
result.current.setCanvasRef(canvasSpy);
|
||||
result.current.setContainerRef(containerSpy);
|
||||
});
|
||||
await waitFor(() => {
|
||||
expect(result.current.canvas).toBe(canvasSpy);
|
||||
});
|
||||
await act(async () => {
|
||||
controlledRiveloadCb();
|
||||
});
|
||||
|
||||
@@ -188,6 +210,11 @@ describe('useRive', () => {
|
||||
await act(async () => {
|
||||
result.current.setCanvasRef(canvasSpy);
|
||||
result.current.setContainerRef(containerSpy);
|
||||
});
|
||||
await waitFor(() => {
|
||||
expect(result.current.canvas).toBe(canvasSpy);
|
||||
});
|
||||
await act(async () => {
|
||||
controlledRiveloadCb();
|
||||
});
|
||||
|
||||
@@ -222,6 +249,11 @@ describe('useRive', () => {
|
||||
await act(async () => {
|
||||
result.current.setCanvasRef(canvasSpy);
|
||||
result.current.setContainerRef(containerSpy);
|
||||
});
|
||||
await waitFor(() => {
|
||||
expect(result.current.canvas).toBe(canvasSpy);
|
||||
});
|
||||
await act(async () => {
|
||||
controlledRiveloadCb();
|
||||
});
|
||||
|
||||
@@ -260,6 +292,11 @@ describe('useRive', () => {
|
||||
await act(async () => {
|
||||
result.current.setContainerRef(containerSpy);
|
||||
result.current.setCanvasRef(canvasSpy);
|
||||
});
|
||||
await waitFor(() => {
|
||||
expect(result.current.canvas).toBe(canvasSpy);
|
||||
});
|
||||
await act(async () => {
|
||||
controlledRiveloadCb();
|
||||
});
|
||||
|
||||
@@ -271,43 +308,6 @@ describe('useRive', () => {
|
||||
expect(containerSpy).toHaveAttribute('style', 'height: 50px;');
|
||||
});
|
||||
|
||||
it('configures a IntersectionObserver on mounting', async () => {
|
||||
const params = {
|
||||
src: 'file-src',
|
||||
};
|
||||
|
||||
const observeMock = jest.fn();
|
||||
|
||||
const restore = global.IntersectionObserver;
|
||||
global.IntersectionObserver = jest.fn().mockImplementation(() => ({
|
||||
observe: observeMock,
|
||||
}));
|
||||
|
||||
const riveMock = {
|
||||
...baseRiveMock,
|
||||
bounds: {
|
||||
maxX: 100,
|
||||
maxY: 50,
|
||||
},
|
||||
};
|
||||
|
||||
// @ts-ignore
|
||||
mocked(rive.Rive).mockImplementation(() => riveMock);
|
||||
|
||||
const canvasSpy = document.createElement('canvas');
|
||||
|
||||
const { result } = renderHook(() => useRive(params));
|
||||
|
||||
await act(async () => {
|
||||
result.current.setCanvasRef(canvasSpy);
|
||||
controlledRiveloadCb();
|
||||
});
|
||||
|
||||
expect(observeMock).toBeCalledWith(canvasSpy);
|
||||
|
||||
global.IntersectionObserver = restore;
|
||||
});
|
||||
|
||||
it('updates the playing animations when the animations param changes', async () => {
|
||||
const params = {
|
||||
src: 'file-src',
|
||||
@@ -336,6 +336,11 @@ describe('useRive', () => {
|
||||
|
||||
await act(async () => {
|
||||
result.current.setCanvasRef(canvasSpy);
|
||||
});
|
||||
await waitFor(() => {
|
||||
expect(result.current.canvas).toBe(canvasSpy);
|
||||
});
|
||||
await act(async () => {
|
||||
controlledRiveloadCb();
|
||||
});
|
||||
|
||||
@@ -379,6 +384,11 @@ describe('useRive', () => {
|
||||
|
||||
await act(async () => {
|
||||
result.current.setCanvasRef(canvasSpy);
|
||||
});
|
||||
await waitFor(() => {
|
||||
expect(result.current.canvas).toBe(canvasSpy);
|
||||
});
|
||||
await act(async () => {
|
||||
controlledRiveloadCb();
|
||||
});
|
||||
|
||||
@@ -405,6 +415,11 @@ describe('useRive', () => {
|
||||
|
||||
await act(async () => {
|
||||
result.current.setCanvasRef(canvasSpy);
|
||||
});
|
||||
await waitFor(() => {
|
||||
expect(result.current.canvas).toBe(canvasSpy);
|
||||
});
|
||||
await act(async () => {
|
||||
controlledRiveloadCb();
|
||||
});
|
||||
|
||||
@@ -428,6 +443,11 @@ describe('useRive', () => {
|
||||
|
||||
await act(async () => {
|
||||
result.current.setCanvasRef(canvasSpy);
|
||||
});
|
||||
await waitFor(() => {
|
||||
expect(result.current.canvas).toBe(canvasSpy);
|
||||
});
|
||||
await act(async () => {
|
||||
controlledRiveloadCb();
|
||||
});
|
||||
|
||||
@@ -456,6 +476,11 @@ describe('useRive', () => {
|
||||
await act(async () => {
|
||||
result.current.setCanvasRef(canvasSpy);
|
||||
result.current.setContainerRef(containerSpy);
|
||||
});
|
||||
await waitFor(() => {
|
||||
expect(result.current.canvas).toBe(canvasSpy);
|
||||
});
|
||||
await act(async () => {
|
||||
controlledRiveloadCb();
|
||||
});
|
||||
|
||||
@@ -483,9 +508,17 @@ describe('useRive', () => {
|
||||
await act(async () => {
|
||||
result.current.setCanvasRef(canvasSpy);
|
||||
result.current.setContainerRef(containerSpy);
|
||||
controlledRiveloadCb();
|
||||
jest.spyOn(containerSpy, 'clientWidth', 'get').mockReturnValue(200);
|
||||
jest.spyOn(containerSpy, 'clientHeight', 'get').mockReturnValue(200);
|
||||
});
|
||||
await waitFor(() => {
|
||||
expect(result.current.canvas).toBe(canvasSpy);
|
||||
});
|
||||
await act(async () => {
|
||||
controlledRiveloadCb();
|
||||
});
|
||||
|
||||
await act(async () => {
|
||||
containerSpy.dispatchEvent(new Event('resize'));
|
||||
});
|
||||
|
||||
@@ -516,7 +549,16 @@ describe('useRive', () => {
|
||||
await act(async () => {
|
||||
result.current.setCanvasRef(canvasSpy);
|
||||
result.current.setContainerRef(containerSpy);
|
||||
});
|
||||
|
||||
await waitFor(() => {
|
||||
expect(result.current.canvas).toBe(canvasSpy);
|
||||
});
|
||||
await act(async () => {
|
||||
controlledRiveloadCb();
|
||||
});
|
||||
|
||||
await act(async () => {
|
||||
jest.spyOn(containerSpy, 'clientWidth', 'get').mockReturnValue(500);
|
||||
jest.spyOn(containerSpy, 'clientHeight', 'get').mockReturnValue(500);
|
||||
containerSpy.dispatchEvent(new Event('resize'));
|
||||
|
||||
142
test/useRiveFile.test.tsx
Normal file
142
test/useRiveFile.test.tsx
Normal file
@@ -0,0 +1,142 @@
|
||||
import { renderHook } from '@testing-library/react-hooks';
|
||||
import { mocked } from 'jest-mock';
|
||||
|
||||
import useRiveFile from '../src/hooks/useRiveFile';
|
||||
import { RiveFile } from '@rive-app/canvas';
|
||||
|
||||
jest.mock('@rive-app/canvas', () => ({
|
||||
RiveFile: jest.fn().mockImplementation(() => ({
|
||||
cleanup: jest.fn(),
|
||||
on: jest.fn(),
|
||||
init: jest.fn(),
|
||||
getInstance: jest.fn(),
|
||||
})),
|
||||
EventType: {
|
||||
Load: 'load',
|
||||
loadError: 'loadError',
|
||||
},
|
||||
}));
|
||||
|
||||
|
||||
describe('useRiveFile', () => {
|
||||
beforeEach(() => {
|
||||
mocked(RiveFile).mockClear();
|
||||
});
|
||||
|
||||
|
||||
|
||||
it('initializes RiveFile with provided parameters', async () => {
|
||||
const params = {
|
||||
src: 'file-src',
|
||||
enableRiveAssetCDN: false
|
||||
};
|
||||
|
||||
const { result } = renderHook(() => useRiveFile(params));
|
||||
|
||||
expect(RiveFile).toHaveBeenCalledWith(params);
|
||||
expect(result.current.riveFile).toBeDefined();
|
||||
});
|
||||
|
||||
it('cleans up RiveFile on unmount', async () => {
|
||||
const params = {
|
||||
src: 'file-src',
|
||||
enableRiveAssetCDN: false
|
||||
};
|
||||
|
||||
const { result, unmount } = renderHook(() => useRiveFile(params));
|
||||
|
||||
const riveInstance = result.current.riveFile;
|
||||
expect(riveInstance).toBeDefined();
|
||||
|
||||
unmount();
|
||||
|
||||
expect(riveInstance?.cleanup).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('does not reinitialize RiveFile if src has not changed', async () => {
|
||||
const params = {
|
||||
src: 'file-src',
|
||||
enableRiveAssetCDN: false
|
||||
};
|
||||
|
||||
const { rerender } = renderHook(() => useRiveFile(params));
|
||||
|
||||
rerender();
|
||||
|
||||
expect(RiveFile).toHaveBeenCalledTimes(1);
|
||||
});
|
||||
|
||||
it('does not reinitialize RiveFile if buffer has not changed', async () => {
|
||||
const params = {
|
||||
buffer: new ArrayBuffer(10),
|
||||
enableRiveAssetCDN: false
|
||||
};
|
||||
|
||||
const { rerender } = renderHook(() => useRiveFile(params));
|
||||
|
||||
rerender();
|
||||
|
||||
expect(RiveFile).toHaveBeenCalledTimes(1);
|
||||
});
|
||||
|
||||
it('reinitializes RiveFile if src changes', async () => {
|
||||
let params = {
|
||||
src: 'file-src',
|
||||
enableRiveAssetCDN: false
|
||||
};
|
||||
|
||||
const { rerender } = renderHook(() => useRiveFile(params));
|
||||
|
||||
params = {
|
||||
src: 'new-file-src',
|
||||
enableRiveAssetCDN: false
|
||||
};
|
||||
|
||||
rerender();
|
||||
|
||||
expect(RiveFile).toHaveBeenCalledTimes(2);
|
||||
});
|
||||
|
||||
it('reinitializes RiveFile if buffer changes', async () => {
|
||||
let params = {
|
||||
buffer: new ArrayBuffer(10),
|
||||
enableRiveAssetCDN: false
|
||||
};
|
||||
|
||||
const { rerender } = renderHook(() => useRiveFile(params));
|
||||
|
||||
params = {
|
||||
buffer: new ArrayBuffer(20),
|
||||
enableRiveAssetCDN: false
|
||||
};
|
||||
|
||||
rerender();
|
||||
|
||||
expect(RiveFile).toHaveBeenCalledTimes(2);
|
||||
});
|
||||
|
||||
it('handles RiveFile initialization failure gracefully', async () => {
|
||||
|
||||
const consoleSpy = jest.spyOn(console, 'error').mockImplementation(() => { });
|
||||
const error = new Error("Initialization failed");
|
||||
|
||||
mocked(RiveFile).mockImplementation(() => {
|
||||
throw error;
|
||||
});
|
||||
|
||||
const params = {
|
||||
src: 'file-src',
|
||||
enableRiveAssetCDN: false,
|
||||
};
|
||||
|
||||
const { result, rerender } = renderHook(() => useRiveFile(params));
|
||||
|
||||
rerender();
|
||||
|
||||
expect(result.current.status).toBe('failed');
|
||||
expect(result.current.riveFile).toBeNull();
|
||||
expect(consoleSpy).toHaveBeenCalledWith(error);
|
||||
|
||||
consoleSpy.mockRestore();
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user