ReactNative实现的横向滑动条
OK,我们先看下效果图



注意使用到了两个库
1.react-native-linear-gradient
2.react-native-gesture-handler
ok,我们看下面的代码
import {Image, TouchableWithoutFeedback, StyleSheet, View} from 'react-native';
import LinearGradient from 'react-native-linear-gradient';
import React from 'react';
import {Gesture,GestureDetector,GestureHandlerRootView,
} from 'react-native-gesture-handler';
export class HorizntalSlider extends React.Component {shouldComponentUpdate(nextProps: Readonly<P>,nextState: Readonly<S>,nextContext: any,): boolean {return false;}constructor(props) {super(props);this.progress = props.initValue;this.step = props.step;this.range = props.max - props.min;this.currentX = 0;this.enable = true;}_setValueChange(value) {this.currentX = value;this.selectedTrack.setNativeProps({style: {width: value},});let indicatorValue = value - 5 > 0 ? value - 5 : 0;this.indicator.setNativeProps({style: {left: indicatorValue - 1},});}componentDidMount(): void {if (this.props) {this.setPowerState(this.props.openState);}}_add() {if (!this.enable) {showToast(this.tips);const {onEnableClick} = this.props;if (onEnableClick) {onEnableClick();}return;}let tempValue = this.progress + this.step;this.progress =tempValue > this.props.max ? this.props.max : tempValue;let styleValue =((this.progress - this.props.min) / this.range) * 250;this._setValueChange(styleValue);const {onLastChange, onChange} = this.props;onChange(this.progress);onLastChange(this.progress);}_reduce() {if (!this.enable) {const {onEnableClick} = this.props;if (onEnableClick) {onEnableClick();}showToast(this.tips);return;}let tempValue = this.progress - this.step;this.progress =tempValue < this.props.min ? this.props.min : tempValue;let styleValue =((this.progress - this.props.min) / this.range) * 250;this._setValueChange(styleValue);const {onLastChange, onChange} = this.props;onChange(this.progress);onLastChange(this.progress);}_onValueChange(x, isFinalize = false) {if (x > 250) {x = 250;}if (x < 0) {x = 0;}this.currentX = x;this.progress = this.props.min + parseInt((x / 250) * this.range);// if (isFinalize) {// const {onLastChange} = this.props;// onLastChange(this.progress);// } else {// const {onChange} = this.props;// onChange(this.progress);// }this._setValueChange(x);}setPowerState(state) {if (!this.props) {return;}if (state === 1) {this.selectedTrack.setNativeProps({style: {width: this.currentX,},});this.indicator.setNativeProps({style: {opacity: 1},});} else {this.selectedTrack.setNativeProps({style: {width: 0},});this.indicator.setNativeProps({style: {opacity: 0},});}}setEnable(isEnable, tips) {if (!this.props) {return;}this.enable = isEnable;this.tips = tips;}gesture = Gesture.Pan().onBegin(e => {this._onValueChange(e.x);}).onUpdate(e => {this._onValueChange(e.x);}).onFinalize(e => {this._onValueChange(e.x, true);});render() {this.currentX = ((this.progress - this.props.min) / this.range) * 250;this.currentX = this.currentX > 0 ? this.currentX : 0;return (<View style={[styles.mainContainer, this.props.style]}><GestureHandlerRootView><GestureDetector gesture={this.gesture}><View style={styles.sliderContainer}><LinearGradientstart={{x: 0, y: 0}}end={{x: 1, y: 0}}colors={['#4372FF', 'white', '#FF4D4F']}style={{width: 252,height: 60,}}/><Viewstyle={{flexDirection: 'row',alignItems: 'center',position: 'absolute',}}><Viewref={c => (this.selectedTrack = c)}style={{width: this.currentX,opacity: 0,height: 60,}}/><Viewstyle={{flex: 1,backgroundColor: '#12161a',opacity: 0.8,height: 60,}}/></View><Viewref={c => (this.indicator = c)}style={[styles.indicator, {left: this.currentX - 7}]}/></View></GestureDetector></GestureHandlerRootView></View>);}
}class Track extends React.Component {constructor(props) {super(props);this.unitViewArr = [];for (let i = 0; i < 42; i++) {this.unitViewArr[i] = i;}}shouldComponentUpdate(nextProps: Readonly<P>,nextState: Readonly<S>,nextContext: any,): boolean {return false;}render() {return (<View style={styles.trackContainer}>{this.unitViewArr.map((item, index) => {return (<Viewkey={index}style={{flexDirection: 'row', alignItems: 'center'}}><Viewstyle={{height: 60,width: 2,opacity: 0,backgroundColor: '#12161a',borderRadius: 100,}}/><Viewstyle={{height: 60, width: 4, backgroundColor: '#12161a'}}/></View>);})}</View>);}
}const styles = StyleSheet.create({mainContainer: {flexDirection: 'row',justifyContent: 'center',alignItems: 'center',},sliderContainer: {position: 'relative',justifyContent: 'center',paddingVertical: 10,marginLeft: 10,marginRight: 8,},trackContainer: {width: 252,flexDirection: 'row',position: 'absolute',},actionImg: {width: 60,height: 60,},thumb: {height: 34,width: 7,backgroundColor: 'transparent',},indicator: {width: 0,height: 0,position: 'absolute',top: -2,borderLeftWidth: 4,borderTopWidth: 4,borderRightWidth: 4,left: -3,borderTopColor: '#FF6A6B',borderLeftColor: 'transparent',borderRightColor: 'transparent',},
});
export default HorizntalSlider;
使用代码如下
<GestureHandlerHorizntalSlidermodel={{initValue: 20,step: 10,max: 100,min: 0,}}></GestureHandlerHorizntalSlider>
拖动条:max(最大值),min(最小值),initValue(当前值),step(步调)
相关文章:
ReactNative实现的横向滑动条
OK,我们先看下效果图 注意使用到了两个库 1.react-native-linear-gradient 2.react-native-gesture-handler ok,我们看下面的代码 import {Image, TouchableWithoutFeedback, StyleSheet, View} from react-native; import LinearGradient from reac…...
华为自动驾驶干不过特斯拉?
文 | AUTO芯球 作者 | 李诞 什么? 华为的智能驾驶方案干不过蔚小理? 特斯拉的智能驾驶[FSD]要甩中国车企几条街? 这华为问界阿维塔刚刚推送“全国都能开”的城区“无图 NCA” 就有黑子来喷了 这是跪久了站不起来了吧 作为玩车14年&…...
docker容器stop流程
从API route开始看StopContainer接口的调用过程。 // NewRouter initializes a new container router func NewRouter(b Backend, decoder httputils.ContainerDecoder) router.Router {r : &containerRouter{backend: b,decoder: decoder,}r.initRoutes()return r } ... …...
生产环境_Spark接收传入的sql并替换sql中的表名与解析_非常NB
背景 开发时遇到一个较为复杂的周期需求,为了适配读取各种数据库中的数据并将数据库数据转换为DataFrame并进行后续的开发分析工作,做了如下代码。 在爷们开发这段生产中的代码,可适配mysql,hive,hbase,gbase等等…...
【issue-YOLO】自定义数据集训练YOLO-v7 Segmentation
1. 拉取代码创建环境 执行nvidia-smi验证cuda环境是否可用;拉取官方代码; clone官方代码仓库 git clone https://github.com/WongKinYiu/yolov7;从main分支切换到u7分支 cd yolov7 && git checkout 44f30af0daccb1a3baecc5d80eae229…...
【八大排序】选择排序 | 堆排序 + 图文详解!!
📷 江池俊: 个人主页 🔥个人专栏: ✅数据结构冒险记 ✅C语言进阶之路 🌅 有航道的人,再渺小也不会迷途。 文章目录 一、选择排序1.1 基本思想1.2 算法步骤 动图演示1.3 代码实现1.4 选择排序特性总结 二…...
C语言贪吃蛇详解
个人简介:双非大二学生 个人博客:Monodye 今日鸡汤:人生就像一盒巧克力,你永远不知道下一块是什么味的 C语言基础刷题:牛客网在线编程_语法篇_基础语法 (nowcoder.com) 一.贪吃蛇游戏背景 贪吃蛇是久负盛名的游戏&…...
go使用gopprof分析内存泄露
假设我们使用的是比如beego这样的网络框架,我们可以这样加代码来使用gopprof来进行内存泄露分析: beego框架加gopprof分析代码: 1.先在router.go里添加路由信息: beego.Router("/debug/pprof", &controllers.ProfController{}) beego.Router("/debug…...
uniapp中组件库Mask 遮罩层 的使用方法
目录 #平台差异说明 #基本使用 #嵌入内容 #遮罩样式 #API #Props #Events #Slot 创建一个遮罩层,用于强调特定的页面元素,并阻止用户对遮罩下层的内容进行操作,一般用于弹窗场景 #平台差异说明 AppH5微信小程序支付宝小程序百度小程…...
【数据结构与算法】(7)基础数据结构之双端队列的链表实现、环形数组实现示例讲解
目录 2.6 双端队列1) 概述2) 链表实现3) 数组实现习题E01. 二叉树 Z 字层序遍历-Leetcode 103 2.6 双端队列 1) 概述 双端队列、队列、栈对比 定义特点队列一端删除(头)另一端添加(尾)First In First Out栈一端删除和添加&…...
2024 高级前端面试题之 前端工程相关 「精选篇」
该内容主要整理关于 前端工程相关模块的相关面试题,其他内容面试题请移步至 「最新最全的前端面试题集锦」 查看。 前端工程相关模块精选篇 1. webpack的基本配置2. webpack高级配置3. webpack性能优化-构建速度4. webpack性能优化-产出代码(线上运行&am…...
CSS常用属性
CSS常用属性 1. 像素的概念 概念:我们的电脑屏幕是,是由一个一个“小点”组成的,每个“小点”,就是一个像素(px)。规律:像素点越小,呈现的内容就越清晰、越细腻。 注意点ÿ…...
AI新宠Arc浏览器真可以取代Chrome吗?
每周跟踪AI热点新闻动向和震撼发展 想要探索生成式人工智能的前沿进展吗?订阅我们的简报,深入解析最新的技术突破、实际应用案例和未来的趋势。与全球数同行一同,从行业内部的深度分析和实用指南中受益。不要错过这个机会,成为AI领…...
基于Java (spring-boot)的实验室管理系统
一、项目介绍 普通用户: 1.登录,注册 2.查看实验室列表信息 3.实验室预约 4.查看预约进度并取消 5.查看公告 6.订阅课程 7.实验室报修 8.修改个人信息 教师登录: 1.查看并审核预约申请 2.查看已审核预约并导出到excel 3.实验室设备管理,报修 …...
Android用setRectToRect实现Bitmap基于Matrix矩阵scale缩放RectF动画,Kotlin(一)
Android用setRectToRect实现Bitmap基于Matrix矩阵scale缩放RectF动画,Kotlin(一) 基于Matrix,控制Bitmap的setRectToRect的目标RectF的宽高。从很小的宽高开始,不断迭代增加setRectToRect的目标RectF的宽高,…...
【AI绘画+Midjourney平替】Fooocus:图像生成、修改软件(Controlnet原作者重新设计的UI+Windows一键部署)
代码:https://github.com/lllyasviel/Fooocus windows一键启动包下载:https://github.com/lllyasviel/Fooocus/releases/download/release/Fooocus_win64_2-1-831.7z B站视频教程:AI绘画入门神器:Fooocus | 简化SD流程,…...
Java技术栈 —— Hive与HBase
Java技术栈 —— Hive与HBase 一、 什么是Hive与HBase二、如何使用Hive与HBase?2.1 Hive2.1.1 安装2.1.2 使用2.1.2.1 使用前准备2.1.2.2 开始使用hive 2.2 HBase2.2.1 安装2.2.2 使用 三、Apache基金会 一、 什么是Hive与HBase 见参考文章。 一、参考文章或视频链…...
【代码随想录-哈希表】有效的字母异位词
💝💝💝欢迎来到我的博客,很高兴能够在这里和您见面!希望您在这里可以感受到一份轻松愉快的氛围,不仅可以获得有趣的内容和知识,也可以畅所欲言、分享您的想法和见解。 推荐:kwan 的首页,持续学习,不断总结,共同进步,活到老学到老导航 檀越剑指大厂系列:全面总结 jav…...
SQL Server之DML触发器
一、如何创建一个触发器呢 触发器的定义语言如下: CREATE [ OR ALTER ] TRIGGER trigger_nameon {table_name | view_name}{for | After | Instead of }[ insert, update,delete ]assql_statement从这个定义语言我们可以知道如下信息: trigger_name&…...
04. 【Linux教程】安装 Linux 操作系统
通过前面的小节学习,我们已经对 Linux 操作系统有了简单的了解,同时也在 Windows 下安装了虚拟机软件 VMware ,那么本节课我们就介绍下如何使用虚拟机软件安装 Linux 操作系统。 通过第一小节的学习我们知道 Linux 有很多的发行版本…...
网络编程(Modbus进阶)
思维导图 Modbus RTU(先学一点理论) 概念 Modbus RTU 是工业自动化领域 最广泛应用的串行通信协议,由 Modicon 公司(现施耐德电气)于 1979 年推出。它以 高效率、强健性、易实现的特点成为工业控制系统的通信标准。 包…...
label-studio的使用教程(导入本地路径)
文章目录 1. 准备环境2. 脚本启动2.1 Windows2.2 Linux 3. 安装label-studio机器学习后端3.1 pip安装(推荐)3.2 GitHub仓库安装 4. 后端配置4.1 yolo环境4.2 引入后端模型4.3 修改脚本4.4 启动后端 5. 标注工程5.1 创建工程5.2 配置图片路径5.3 配置工程类型标签5.4 配置模型5.…...
微软PowerBI考试 PL300-选择 Power BI 模型框架【附练习数据】
微软PowerBI考试 PL300-选择 Power BI 模型框架 20 多年来,Microsoft 持续对企业商业智能 (BI) 进行大量投资。 Azure Analysis Services (AAS) 和 SQL Server Analysis Services (SSAS) 基于无数企业使用的成熟的 BI 数据建模技术。 同样的技术也是 Power BI 数据…...
通过Wrangler CLI在worker中创建数据库和表
官方使用文档:Getting started Cloudflare D1 docs 创建数据库 在命令行中执行完成之后,会在本地和远程创建数据库: npx wranglerlatest d1 create prod-d1-tutorial 在cf中就可以看到数据库: 现在,您的Cloudfla…...
CentOS下的分布式内存计算Spark环境部署
一、Spark 核心架构与应用场景 1.1 分布式计算引擎的核心优势 Spark 是基于内存的分布式计算框架,相比 MapReduce 具有以下核心优势: 内存计算:数据可常驻内存,迭代计算性能提升 10-100 倍(文档段落:3-79…...
HBuilderX安装(uni-app和小程序开发)
下载HBuilderX 访问官方网站:https://www.dcloud.io/hbuilderx.html 根据您的操作系统选择合适版本: Windows版(推荐下载标准版) Windows系统安装步骤 运行安装程序: 双击下载的.exe安装文件 如果出现安全提示&…...
蓝桥杯 冶炼金属
原题目链接 🔧 冶炼金属转换率推测题解 📜 原题描述 小蓝有一个神奇的炉子用于将普通金属 O O O 冶炼成为一种特殊金属 X X X。这个炉子有一个属性叫转换率 V V V,是一个正整数,表示每 V V V 个普通金属 O O O 可以冶炼出 …...
A2A JS SDK 完整教程:快速入门指南
目录 什么是 A2A JS SDK?A2A JS 安装与设置A2A JS 核心概念创建你的第一个 A2A JS 代理A2A JS 服务端开发A2A JS 客户端使用A2A JS 高级特性A2A JS 最佳实践A2A JS 故障排除 什么是 A2A JS SDK? A2A JS SDK 是一个专为 JavaScript/TypeScript 开发者设计的强大库ÿ…...
【C++进阶篇】智能指针
C内存管理终极指南:智能指针从入门到源码剖析 一. 智能指针1.1 auto_ptr1.2 unique_ptr1.3 shared_ptr1.4 make_shared 二. 原理三. shared_ptr循环引用问题三. 线程安全问题四. 内存泄漏4.1 什么是内存泄漏4.2 危害4.3 避免内存泄漏 五. 最后 一. 智能指针 智能指…...
Windows安装Miniconda
一、下载 https://www.anaconda.com/download/success 二、安装 三、配置镜像源 Anaconda/Miniconda pip 配置清华镜像源_anaconda配置清华源-CSDN博客 四、常用操作命令 Anaconda/Miniconda 基本操作命令_miniconda创建环境命令-CSDN博客...
