当前位置: 首页 > news >正文

react-native从入门到实战系列教程一Swiper组件的使用及bug修复

轮播图,在app中随处可见,这么重要的功能我们怎么可能不学习下在react-native中的实现方式。
依然是第三方组件react-native-swiper

官网地址

https://www.npmjs.com/package/react-native-swiper

组件使用的组件及事件参考官方即可。

实现效果

  • 官网示例实现
    请添加图片描述
  • 业务需求实现
    请添加图片描述

代码实现

import {View,Text,Image,StyleSheet,Dimensions,ScrollView,
} from 'react-native';
import {useEffect, useState} from 'react';
import Logo from '../../assets/images/logo.png';
import Ionicons from 'react-native-vector-icons/Ionicons';
import Swiper from 'react-native-swiper';function HomeScreen() {const windowWidth = Dimensions.get('window').width;return (<Viewstyle={{flex: 1,justifyContent: 'flex-start',alignItems: 'center',width: '100%',backgroundColor: '#F5FCFF',}}><View style={styles.box}><Swiper style={styles.swiper} height={200} horizontal={true} autoplay><Imagesource={{uri: 'https://img-s-msn-com.akamaized.net/tenant/amp/entityid/AA1o9rRO.img?w=768&h=538&m=6&x=297&y=153&s=399&d=155',}}style={styles.img}/><Imagesource={{uri: 'https://img-s-msn-com.akamaized.net/tenant/amp/entityid/BB1r4EGh.img?w=640&h=427&m=6&x=160&y=169&s=82&d=82',}}style={styles.img}/><Imagesource={{uri: 'https://img-s-msn-com.akamaized.net/tenant/amp/entityid/BB1r4vmA.img?w=640&h=360&m=6&x=198&y=83&s=103&d=103',}}style={styles.img}/></Swiper></View></View>);
}
const styles = StyleSheet.create({img: {width: Dimensions.get('window').width,height: 200,resizeMode: 'cover',},box: {height: 200,backgroundColor: '#F5FCFF',},
});
export default HomeScreen;

bug修复

可能是截图软件的原因,没有捕捉到轮播在自动循环播放的时候,会出现闪烁的闪电现象。后来发现好多人遇到,我这里是使用模拟器,不知道真机效果是不是也这样。

  • 修复方式
    removeClippedSubviews={false}在组件上加上这个配置即可修复闪烁现象
<SwiperremoveClippedSubviews={false}style={styles.swiper}height={200}horizontal={true}autoplay><Imagesource={{uri: 'https://img-s-msn-com.akamaized.net/tenant/amp/entityid/AA1o9rRO.img?w=768&h=538&m=6&x=297&y=153&s=399&d=155',}}style={styles.img}/><Imagesource={{uri: 'https://img-s-msn-com.akamaized.net/tenant/amp/entityid/BB1r4EGh.img?w=640&h=427&m=6&x=160&y=169&s=82&d=82',}}style={styles.img}/><Imagesource={{uri: 'https://img-s-msn-com.akamaized.net/tenant/amp/entityid/BB1r4vmA.img?w=640&h=360&m=6&x=198&y=83&s=103&d=103',}}style={styles.img}/></Swiper>

官方issue没关闭,但是有老外解决了!!
https://github.com/leecade/react-native-swiper/issues/1267

http://www.lryc.cn/news/413880.html

相关文章:

  • springboot开发的常用注解总结-配置组件类注解
  • DataX 最新版本安装部署
  • 【架构】应用保护
  • 从核心到边界:六边形、洋葱与COLA架构的深度解析
  • 04-Fastjson反序列化漏洞
  • ABC365(A-D)未补
  • Python用png生成不同尺寸的图标
  • 1688中国站获得工厂档案信息 API
  • 定时任务框架 xxl-job
  • C/C++关键字大全
  • ROS2 Linux Mint 22 安装教程
  • 快速将网站从HTTP升级为HTTPS
  • Qt程序移植至Arm开发板
  • 删除分区 全局索引 drop partition global index Statistics变化
  • git回退未commit、回退已commit、回退已push、合并某一次commit到另一个分支
  • yolov8pose 部署rknn(rk3588)、部署地平线Horizon、部署TensorRT,部署工程难度小、模型推理速度快,DFL放后处理中
  • 程序员找工作之操作系统面试题总结分析
  • TypeScript 迭代器和生成器详解
  • echarts 极坐标柱状图 如何定义柱子颜色
  • JavaScript模块化
  • 文件包含漏洞Tomato靶机渗透_详解
  • 湖北汽车工业学院-高等数学考纲
  • Linux:Xshell相关配置及前期准备
  • 模型 正态分布(通俗解读)
  • 安装了Vue-pdf后,打包文件多出了worker.js和worker.js.gz
  • 使用excel生成国际化多语言js文件的脚本
  • 【蝉联】摩斯再次获得“中国隐私计算市场份额第一”
  • 安装 qcloud-python-sts 失败 提示 gbk codecs decode byte 应该如何解决
  • mv:自动对焦代码
  • 【C++】数组案例 五只小猪称体重