首先创建简单的react-native项目,创建一个文件夹。然后用命令符输入
react-native init swiper
创建完成之后开发项目,我用的vs
打开控制台,安装swiper依赖。
安装:npm i react-native-swiper --save
查看:npm view react-native-swiper
删除:npm rm react-native-swiper --save
这里还需要 npm i 下更新下本地的依赖库
启动app项目
ios: react-native run-ios
android: react-native run-android
开始上码,在src里面创建个components文件夹下边创建个swiper.js文件,以及index.js,加上说明文档
import PropTypes from 'prop-types';
import React, { Component } from 'react';
import { StyleSheet, TouchableWithoutFeedback, View } from 'react-native';
import RNSwiper from 'react-native-swiper';
const styles = StyleSheet.create({
activeDotWrapperStyle: {
//圆点样式
},
activeDotStyle: {
//圆点样式
},
dotStyle: {
//圆点样式
}
});
const activeDot = (
<View style={styles.activeDotWrapperStyle}>
<View style={styles.activeDotStyle} />
</View>
);
const dot = <View style={styles.dotStyle} />;
export class Carousel extends Component {
// Define component prop list
static propTypes = {
data: PropTypes.array,
height: PropTypes.number,
onPressItem: PropTypes.func,
renderItem: PropTypes.func.isRequired,
autoplay: PropTypes.bool,
autoplayTimeout: PropTypes.number
};
// Define props default value
static defaultProps = {
data: [],
height: 150,
autoplay: true,
autoplayTimeout: 2.5,
onPressItem: () => {},
renderItem: () => {}
};
// Define inner state
state = {
showSwiper: false
};
constructor(props) {
super(props);
this.handleItemPress = this.handleItemPress.bind(this);
}
componentDidMount() {
setTimeout(() => {
this.setState({ showSwiper: true });
});
}
handleItemPress(item) {
this.props.onPressItem(item);
}
_renderSwiperItem(item, index) {
return (
<TouchableWithoutFeedback key={index} onPress={() => this.handleItemPress(item)}>
<View style={[{ flex: 1 }]}>{this.props.renderItem(item)}</View>
</TouchableWithoutFeedback>
);
}
render() {
return this.props.data.length === 0 || !this.state.showSwiper "htmlcode">
import { Carousel } from './carousel/Carousel';
export { Carousel };
公共组件库
这里用于放置与业务无关的公共组件。组件实现必须考虑灵活性,扩展性,不能包含具体的业务逻辑。
组件必须以 你做的业务命名 为前缀,如 TryCarousel.js 。每个组件必须单独放在目录中,目录必须全小写(中横线分割),如 carousel/TryCarousel.js 。
一个基本的组件结构:
import PropTypes from 'prop-types';
import React, { Component } from 'react';
export class TryCarousel extends Component {
// Define component prop list
static propTypes = {};
// Define props default value
static defaultProps = {};
// Define inner state
state = {};
constructor(props) {
super(props);
}
// LifeCycle Hooks
// Prototype Functions
// Ensure the latest function is render
render() {}
}
组件列表
carousel(轮播组件)
主要用于通用的图片轮播,能够提供点击事件响应。
Usage:
Props:
属性
描述
类型
默认值
data
Carousel数据源
Array
-
height
Carousel的高度
number
150
onPressItem
点击Carousel Item的时候触发
fn
-
renderItem
具体的渲染Item的方法,请参考FlatList
fn
-
autoplay
是否自动切换
bool
true
autoplayTimeout
Item自动切换的时间间隔(单位s)
number
2.5
需要导入的地方
import { HigoCarousel } from '../../components';
<Carousel
data={} //接受的数据
onPressItem={} //点击事件
height={} //图片高度
autoplay={} //是否自动播放
autoplayTimeout={} //过渡时间
renderItem={item => {
return <Image source={{ uri: item.imageSource }} style={{ flex: 1 }} />;
}} //图片
/>
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持。
免责声明:本站文章均来自网站采集或用户投稿,网站不提供任何软件下载或自行开发的软件! 如有用户或公司发现本站内容信息存在侵权行为,请邮件告知! 858582#qq.com
RTX 5090要首发 性能要翻倍!三星展示GDDR7显存
三星在GTC上展示了专为下一代游戏GPU设计的GDDR7内存。
首次推出的GDDR7内存模块密度为16GB,每个模块容量为2GB。其速度预设为32 Gbps(PAM3),但也可以降至28 Gbps,以提高产量和初始阶段的整体性能和成本效益。
据三星表示,GDDR7内存的能效将提高20%,同时工作电压仅为1.1V,低于标准的1.2V。通过采用更新的封装材料和优化的电路设计,使得在高速运行时的发热量降低,GDDR7的热阻比GDDR6降低了70%。
更新日志
- 小骆驼-《草原狼2(蓝光CD)》[原抓WAV+CUE]
- 群星《欢迎来到我身边 电影原声专辑》[320K/MP3][105.02MB]
- 群星《欢迎来到我身边 电影原声专辑》[FLAC/分轨][480.9MB]
- 雷婷《梦里蓝天HQⅡ》 2023头版限量编号低速原抓[WAV+CUE][463M]
- 群星《2024好听新歌42》AI调整音效【WAV分轨】
- 王思雨-《思念陪着鸿雁飞》WAV
- 王思雨《喜马拉雅HQ》头版限量编号[WAV+CUE]
- 李健《无时无刻》[WAV+CUE][590M]
- 陈奕迅《酝酿》[WAV分轨][502M]
- 卓依婷《化蝶》2CD[WAV+CUE][1.1G]
- 群星《吉他王(黑胶CD)》[WAV+CUE]
- 齐秦《穿乐(穿越)》[WAV+CUE]
- 发烧珍品《数位CD音响测试-动向效果(九)》【WAV+CUE】
- 邝美云《邝美云精装歌集》[DSF][1.6G]
- 吕方《爱一回伤一回》[WAV+CUE][454M]

