manjiz / react-native-swiper Goto Github PK
View Code? Open in Web Editor NEWNot the best Swiper component for React Native.
License: MIT License
Not the best Swiper component for React Native.
License: MIT License
When I use Taro.Swiper on my project, I found the Swiper component's onChange callback does not working at React Native Platform.
I see the the code below in your index.js
onLayout = (event: LayoutChangeEvent) => {
const { loop } = this.props
const {
index,
total,
dir,
width,
height,
} = this.state
const { width: layoutWidth, height: layoutHeight } = event.nativeEvent.layout // <== here
// const layoutWidth = Math.round(event.nativeEvent.layout.width)
// const layoutHeight = Math.round(event.nativeEvent.layout.height)
let offsetWouldBeSet: Partial<Offset> = this.realtimeOffset = {}
const stateWouldBeSet: any = { width: layoutWidth, height: layoutHeight }
if (total > 1) {
let actualIndex = index
loop && actualIndex++
offsetWouldBeSet = getOffset(dir, actualIndex, layoutWidth, layoutHeight)
}
// only update the offset in state if needed, updating offset while swiping
// causes some bad jumping / stuttering
if (layoutWidth !== width || layoutHeight !== height) {
stateWouldBeSet.offset = offsetWouldBeSet
}
this.setState(stateWouldBeSet)
}
then I found that onLayout method triggered every few milliseconds , and it lead to a huge lag .
if I enable the 2 row below
// const layoutWidth = Math.round(event.nativeEvent.layout.width)
// const layoutHeight = Math.round(event.nativeEvent.layout.height)
this problem will be resolved .
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.