React-native中实现折叠效果

要实现这个折叠效果,,首先你需要一个 react-native-collapsible 组件

其实效果很简单,,粘贴即可用,内容自己定义

'use strict';
import React, {Component} from 'react'
import {
    View,
    Text,
    Image,
    ScrollView,
    StyleSheet,
} from 'react-native'
import Accordion from 'react-native-collapsible/Accordion';
import Icon from 'react-native-vector-icons/Ionicons';

const CONTENT = [
    {
        title: '标题1',
        content: '内容1',
    },
    {
        title: '标题2',
        content: '内容2',
    },
    {
        title: '标题3',
        content: '内容3',
    },
    {
       title: '标题4',
        content: '内容4',
    },
    {
       title: '标题5',
        content: '内容5',
    },
];

export default class Fold extends Component {

    // 构造
    constructor(props) {
        super(props);
        // 初始状态
        this.state = {
            activeSection: false,
        };
    }

    _setSection(section) {
        this.setState({ activeSection: section });
    }

    _renderHeader(section,isActive) {
        return (
            <View style={styles.active}>
                <Text>{section.title}</Text>
                <Icon name={isActive ? 'ios-arrow-down':'ios-arrow-down'} size={22} color={'#e9e9ef'} style={{paddingHorizontal:p(20)}}/>
            </View>
        );
    }

    _renderContent(section) {
        return (
            <View style={styles.inactive}>
                <Text style={{margin: p(20)}}>{section.content}</Text>
            </View>
        );
    }
    render() {
        return (
            <View style={styles.container}>
                <ScrollView style={{flex: 1, paddingTop: p(20), }}>
                    <Accordion
                        activeSection={this.state.activeSection}
                        sections={CONTENT}
                        renderHeader={this._renderHeader}
                        renderContent={this._renderContent}
                        duration={400}
                        onChange={this._setSection.bind(this)}
                    />
                </ScrollView>
            </View>
        )
    }
}

const styles = StyleSheet.create({
    container: {
        flex: 1,
    },
    active: {
        height: p(80),
        borderBottomWidth: StyleSheet.hairlineWidth,
        borderBottomColor: '#ddd',
        alignItems: 'center',
        justifyContent: 'space-between',
        flexDirection: 'row',
        paddingLeft: p(15),
        backgroundColor: 'rgba(255,255,255,1)',

    },
    inactive: {
        backgroundColor: 'rgba(245,252,255,1)',
    },
})

亲测可以直接使用。。。

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
要在 React Native 实现声波纹效果,你可以使用第三方组件 react-native-audio-record-view,该组件提供了一个可自定义的声音波形视图,可以用来显示音频波形。 以下是实现步骤: 1. 在你的 React Native 项目安装 react-native-audio-record-view 组件: ``` npm install react-native-audio-record-view --save ``` 2. 导入 AudioRecordView 组件: ```javascript import AudioRecordView from 'react-native-audio-record-view'; ``` 3. 在组件使用 AudioRecordView: ```javascript <AudioRecordView width={200} height={100} waveColor={'#ffffff'} waveFillColor={'#000000'} waveLineWidth={2} waveLineGap={6} waveLineNum={5} recordTime={60} onRecordStart={this.onRecordStart} onRecordStop={this.onRecordStop} /> ``` 其,width 和 height 属性设置声波纹视图的宽度和高度;waveColor,waveFillColor,waveLineWidth,waveLineGap 和 waveLineNum 属性设置声波纹的颜色、填充颜色、线宽、线间距和线数;recordTime 属性设置录音时长;onRecordStart 和 onRecordStop 属性设置开始录音和停止录音的回调函数。 4. 实现 onRecordStart 和 onRecordStop 回调函数: ```javascript onRecordStart = () => { // 开始录音回调函数 } onRecordStop = (audioPath) => { // 停止录音回调函数 // audioPath 参数为录音文件的路径 } ``` 在开始录音回调函数,你可以调用第三方库 react-native-audio-record 来开始录音。在停止录音回调函数,你可以使用第三方库 react-native-audio-toolkit 来处理录音文件,并将音频数据传递给 AudioRecordView 组件来显示声波纹效果。 希望这可以帮到你!

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值