1- import  React ,  {  FunctionComponent  }  from  'react' 
1+ import  React ,  {  FunctionComponent ,   useEffect ,   useState  }  from  'react' 
22
3- import  {  ITouchEvent ,   View  }  from  '@tarojs/components' 
3+ import  {  View  }  from  '@tarojs/components' 
44import  classNames  from  'classnames' 
5+ import  {  Loading1  }  from  '@nutui/icons-react-taro' 
56import  {  ComponentDefaults  }  from  '@/utils/typings' 
67import  {  usePropsValue  }  from  '@/hooks/use-props-value' 
78import  {  useRtl  }  from  '@/packages/configprovider/index.taro' 
@@ -37,6 +38,12 @@ export const Switch: FunctionComponent<Partial<TaroSwitchProps>> = (props) => {
3738    defaultValue : defaultChecked , 
3839  } ) 
3940
41+   useEffect ( ( )  =>  { 
42+     changing  &&  setChanging ( false ) 
43+   } ,  [ value ] ) 
44+ 
45+   const  [ changing ,  setChanging ]  =  useState ( false ) 
46+ 
4047  const  classes  =  ( )  =>  { 
4148    return  classNames ( [ 
4249      classPrefix , 
@@ -49,20 +56,16 @@ export const Switch: FunctionComponent<Partial<TaroSwitchProps>> = (props) => {
4956    ] ) 
5057  } 
5158
52-   const  onClick  =  ( 
53-     event : React . MouseEvent < Element ,  MouseEvent >  |  ITouchEvent 
54-   )  =>  { 
55-     if  ( disabled )  return 
56-     onChange  &&  onChange ( ! value ,  event ) 
59+   const  onClick  =  ( )  =>  { 
60+     if  ( disabled  ||  changing )  return 
61+     if  ( props . onChange )  { 
62+       setChanging ( true ) 
63+       props . onChange ( ! value ) 
64+     } 
5765    setValue ( ! value ) 
5866  } 
5967  return  ( 
60-     < View 
61-       className = { classes ( ) } 
62-       onClick = { ( e )  =>  onClick ( e ) } 
63-       style = { style } 
64-       { ...rest } 
65-     > 
68+     < View  className = { classes ( ) }  onClick = { onClick }  style = { style }  { ...rest } > 
6669      < View 
6770        className = { classNames ( [ 
6871          [ `${ classPrefix }  ] , 
@@ -77,8 +80,14 @@ export const Switch: FunctionComponent<Partial<TaroSwitchProps>> = (props) => {
7780          } , 
7881        ] ) } 
7982      > 
80-         { ! value  &&  ! activeText  &&  ( 
81-           < View  className = { `${ classPrefix }  }  /> 
83+         { changing  ? ( 
84+           < Loading1  /> 
85+         )  : ( 
86+           < > 
87+             { ! value  &&  ! activeText  &&  ( 
88+               < View  className = { `${ classPrefix }  }  /> 
89+             ) } 
90+           </ > 
8291        ) } 
8392      </ View > 
8493      { activeText  &&  ( 
0 commit comments