在重新设置的底部工作表中单击onPress存在于另一个组件中时,如何设置状态?

问题描述

我正在尝试在Camera.js组件中实现Reanimated底页。在我的renderContent道具中,我渲染了另一个组件(MusicIcon2.js),在MusicICon2.js内部,我正在使用另一个包含可触摸不透明度的组件MusicIcon1。我想设置“ Reanimated底部”页面中存在的这种可触摸不透明状态时,在Camera.js中显示状态songCamera

我无法执行此操作。请帮我解决这个问题。我已经附上了代码。

我在这里使用了复活的底页库。

!----- Camera.js ----!

import BottomSheet from 'reanimated-bottom-sheet';

class CameraScreen extends Component{
 constructor(props){
    super(props);
    this.state={
           songCamera:'',}
 }

setMusic=()=>{
  
  return(
    <View style={{
      
     width:width-20,height:600,backgroundColor:'#fff',borderRadius:25,marginHorizontal:10,}}>
       <Text style={{alignSelf:'center'}}> Select a Song </Text>
        <MusicIcon2/>
    </View>
     

  )
}

bs = React.createRef();
  render(){    
    return(
       <View>
                  <BottomSheet
                  ref={this.bs}
                  snapPoints={[600,0]}
                  initialSnap={1}
                  enabledContentGestureInteraction={true}
                  renderContent={this.setMusic}                 
                   />
                   <TouchableOpacity
                  style={styles.musicConatiner} onPress={()=>{this.bs.current.snapTo(0)}}>
                  <Icon name='music' size={27} color='rgba(250,250,0.7)' />
                </TouchableOpacity>
         </View>
       )
     }
  }

!---- MusicIcon2.js ----!

export default class Music extends Component {
 render() {
        return (
                 <View>
                       <MusicIcon1 title='Next to You' publishby='Black shalton' time='0.16' />
                 </View>
               )
          }
}

!---- MusicIcon1.js ---!

export default function MusicIcon(props) {
      const { title,publishby,time,...otherProps } = props;
       return (
               <>
                  <TouchableOpacity onPress={()=>{   //code to update the state songCamera of Camera.js
                                                    bs.current.snapTo(1)}}>
                                                          
                                                         
                       <Icon name='plus' size={20} color='#202124' />
                   </TouchableOpacity>
              </>
             )
 }

单击“加号”图标,状态songCamera应更新为abc.mp3。如何解决这个问题。

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

相关问答

依赖报错 idea导入项目后依赖报错,解决方案:https://blog....
错误1:代码生成器依赖和mybatis依赖冲突 启动项目时报错如下...
错误1:gradle项目控制台输出为乱码 # 解决方案:https://bl...
错误还原:在查询的过程中,传入的workType为0时,该条件不起...
报错如下,gcc版本太低 ^ server.c:5346:31: 错误:‘struct...