@@ -108,7 +108,7 @@ const SpineEditor = ({
108108 } ,
109109 [ getResource ]
110110 ) ;
111- const getSkeleton = React . useCallback (
111+ const loadSkeleton = React . useCallback (
112112 ( spineResourceName : string ) => {
113113 const jsonResourcesMapping = getEmbeddedResourcesMapping (
114114 spineResourceName
@@ -132,25 +132,43 @@ const SpineEditor = ({
132132 )
133133 return Promise . resolve ( undefined ) ;
134134
135- return PixiResourcesLoader . getSpineData ( project , spineResourceName ) . then (
136- newSkeleton => {
137- setSkeleton ( newSkeleton ) ;
135+ return PixiResourcesLoader . getSpineData ( project , spineResourceName ) ;
136+ } ,
137+ [ project , getEmbeddedResourcesMapping ]
138+ ) ;
139+ const [ sourceSelectOptions , setSourceSelectOptions ] = React . useState < Array < Object >> ( [ ] ) ;
140+ const spineResourceName = properties . get ( 'spineResourceName' ) . getValue ( ) ;
138141
139- return newSkeleton ;
142+ React . useEffect (
143+ ( ) => {
144+ ( async ( ) => {
145+ const skeleton = await loadSkeleton ( spineResourceName ) ;
146+
147+ setSkeleton ( skeleton ) ;
148+
149+ if ( skeleton ) {
150+ setSourceSelectOptions (
151+ skeleton . animations . map ( animation => (
152+ < SelectOption
153+ key = { animation . name }
154+ value = { animation . name }
155+ label = { animation . name }
156+ shouldNotTranslate
157+ />
158+ ) )
159+ ) ;
140160 }
141- ) ;
161+ } ) ( ) ;
142162 } ,
143- [ project , getEmbeddedResourcesMapping ]
163+ [ loadSkeleton , setSourceSelectOptions , spineResourceName ]
144164 ) ;
145- getSkeleton ( properties . get ( 'spineResourceName' ) . getValue ( ) ) ;
146165
147166 const onChangeSpineResourceName = React . useCallback (
148- ( spineResourceName : string ) => {
149- getSkeleton ( spineResourceName ) . then ( newSkeleton => {
150- spineConfiguration . removeAllAnimations ( ) ;
151- } ) ;
167+ ( ) => {
168+ spineConfiguration . removeAllAnimations ( ) ;
169+ forceUpdate ( ) ;
152170 } ,
153- [ getSkeleton , spineConfiguration ]
171+ [ forceUpdate , spineConfiguration ]
154172 ) ;
155173
156174 const scanNewAnimations = React . useCallback (
@@ -314,19 +332,6 @@ const SpineEditor = ({
314332 ]
315333 ) ;
316334
317- const sourceSelectOptions = skeleton
318- ? skeleton . animations . map ( animation => {
319- return (
320- < SelectOption
321- key = { animation . name }
322- value = { animation . name }
323- label = { animation . name }
324- shouldNotTranslate
325- />
326- ) ;
327- } )
328- : [ ] ;
329-
330335 return (
331336 < >
332337 < ScrollView ref = { scrollView } >
0 commit comments