Skip to content

Commit

Permalink
Add lag to animation render
Browse files Browse the repository at this point in the history
  • Loading branch information
davidjerleke committed May 2, 2023
1 parent 83e76fb commit 85a6458
Show file tree
Hide file tree
Showing 50 changed files with 273 additions and 306 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ const EmblaCarousel = (props) => {
Object.assign(newEngine[engineModule], oldEngine[engineModule])
})

newEngine.translate.to(oldEngine.location)
newEngine.translate.to(oldEngine.location.value)
const { index } = newEngine.scrollTarget.byDistance(0, false)
newEngine.index.set(index)
newEngine.animation.start()
Expand All @@ -48,7 +48,7 @@ const EmblaCarousel = (props) => {
const engine = emblaApi.internalEngine()

if (hasMoreToLoadRef.current && engine.dragHandler.pointerDown()) {
const boundsActive = engine.limit.reachedMax(engine.target.get())
const boundsActive = engine.limit.reachedMax(engine.target.value)
engine.scrollBounds.toggleActive(boundsActive)
emblaApi.on('pointerUp', reloadAfterPointerUp)
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ const EmblaCarousel: React.FC<PropType> = (props) => {
Object.assign(newEngine[engineModule], oldEngine[engineModule])
})

newEngine.translate.to(oldEngine.location)
newEngine.translate.to(oldEngine.location.value)
const { index } = newEngine.scrollTarget.byDistance(0, false)
newEngine.index.set(index)
newEngine.animation.start()
Expand All @@ -65,7 +65,7 @@ const EmblaCarousel: React.FC<PropType> = (props) => {
const engine = emblaApi.internalEngine()

if (hasMoreToLoadRef.current && engine.dragHandler.pointerDown()) {
const boundsActive = engine.limit.reachedMax(engine.target.get())
const boundsActive = engine.limit.reachedMax(engine.target.value)
engine.scrollBounds.toggleActive(boundsActive)
emblaApi.on('pointerUp', reloadAfterPointerUp)
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ export const IosPickerItem = (props) => {

emblaApi.on('pointerUp', () => {
const { scrollTo, target, location } = emblaApi.internalEngine()
const diffToTarget = target.get() - location.get()
const diffToTarget = target.value - location.value
const factor = Math.abs(diffToTarget) < WHEEL_ITEM_SIZE / 2.5 ? 10 : 0.1
const distance = diffToTarget * factor
scrollTo.distance(distance, true)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ export const IosPickerItem: React.FC<PropType> = (props) => {

emblaApi.on('pointerUp', () => {
const { scrollTo, target, location } = emblaApi.internalEngine()
const diffToTarget = target.get() - location.get()
const diffToTarget = target.value - location.value
const factor = Math.abs(diffToTarget) < WHEEL_ITEM_SIZE / 2.5 ? 10 : 0.1
const distance = diffToTarget * factor
scrollTo.distance(distance, true)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,11 @@ const EmblaCarousel = (props) => {
const scrollProgress = emblaApi.scrollProgress()

const styles = emblaApi.scrollSnapList().map((scrollSnap, index) => {
if (!emblaApi.slidesInView().includes(index)) return 0
let diffToTarget = scrollSnap - scrollProgress

if (engine.options.loop) {
engine.slideLooper.loopPoints.forEach((loopItem) => {
const target = loopItem.target().get()
const target = loopItem.target()
if (index === loopItem.index && target !== 0) {
const sign = Math.sign(target)
if (sign === -1) diffToTarget = scrollSnap - (1 + scrollProgress)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,11 @@ const EmblaCarousel: React.FC<PropType> = (props) => {
const scrollProgress = emblaApi.scrollProgress()

const styles = emblaApi.scrollSnapList().map((scrollSnap, index) => {
if (!emblaApi.slidesInView().includes(index)) return 0
let diffToTarget = scrollSnap - scrollProgress

if (engine.options.loop) {
engine.slideLooper.loopPoints.forEach((loopItem) => {
const target = loopItem.target().get()
const target = loopItem.target()
if (index === loopItem.index && target !== 0) {
const sign = Math.sign(target)
if (sign === -1) diffToTarget = scrollSnap - (1 + scrollProgress)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,11 @@ const EmblaCarousel = (props) => {
const scrollProgress = emblaApi.scrollProgress()

const styles = emblaApi.scrollSnapList().map((scrollSnap, index) => {
if (!emblaApi.slidesInView().includes(index)) return 0
let diffToTarget = scrollSnap - scrollProgress

if (engine.options.loop) {
engine.slideLooper.loopPoints.forEach((loopItem) => {
const target = loopItem.target().get()
const target = loopItem.target()
if (index === loopItem.index && target !== 0) {
const sign = Math.sign(target)
if (sign === -1) diffToTarget = scrollSnap - (1 + scrollProgress)
Expand Down Expand Up @@ -58,7 +57,7 @@ const EmblaCarousel = (props) => {
className="embla__parallax__layer"
style={{
...(tweenValues.length && {
transform: `translateX(${tweenValues[index]}%)`,
transform: `translate3d(${tweenValues[index]}%,0px,0px)`,
}),
}}
>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,11 @@ const EmblaCarousel: React.FC<PropType> = (props) => {
const scrollProgress = emblaApi.scrollProgress()

const styles = emblaApi.scrollSnapList().map((scrollSnap, index) => {
if (!emblaApi.slidesInView().includes(index)) return 0
let diffToTarget = scrollSnap - scrollProgress

if (engine.options.loop) {
engine.slideLooper.loopPoints.forEach((loopItem) => {
const target = loopItem.target().get()
const target = loopItem.target()
if (index === loopItem.index && target !== 0) {
const sign = Math.sign(target)
if (sign === -1) diffToTarget = scrollSnap - (1 + scrollProgress)
Expand Down Expand Up @@ -63,7 +62,7 @@ const EmblaCarousel: React.FC<PropType> = (props) => {
className="embla__parallax__layer"
style={{
...(tweenValues.length && {
transform: `translateX(${tweenValues[index]}%)`,
transform: `translate3d(${tweenValues[index]}%,0px,0px)`,
}),
}}
>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,11 @@ const EmblaCarousel = (props) => {
const scrollProgress = emblaApi.scrollProgress()

const styles = emblaApi.scrollSnapList().map((scrollSnap, index) => {
if (!emblaApi.slidesInView().includes(index)) return 0
let diffToTarget = scrollSnap - scrollProgress

if (engine.options.loop) {
engine.slideLooper.loopPoints.forEach((loopItem) => {
const target = loopItem.target().get()
const target = loopItem.target()
if (index === loopItem.index && target !== 0) {
const sign = Math.sign(target)
if (sign === -1) diffToTarget = scrollSnap - (1 + scrollProgress)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,11 @@ const EmblaCarousel: React.FC<PropType> = (props) => {
const scrollProgress = emblaApi.scrollProgress()

const styles = emblaApi.scrollSnapList().map((scrollSnap, index) => {
if (!emblaApi.slidesInView().includes(index)) return 0
let diffToTarget = scrollSnap - scrollProgress

if (engine.options.loop) {
engine.slideLooper.loopPoints.forEach((loopItem) => {
const target = loopItem.target().get()
const target = loopItem.target()
if (index === loopItem.index && target !== 0) {
const sign = Math.sign(target)
if (sign === -1) diffToTarget = scrollSnap - (1 + scrollProgress)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ const EmblaCarousel: React.FC<PropType> = (props) => {
Object.assign(newEngine[engineModule], oldEngine[engineModule])
})

newEngine.translate.to(oldEngine.location)
newEngine.translate.to(oldEngine.location.value)
const { index } = newEngine.scrollTarget.byDistance(0, false)
newEngine.index.set(index)
newEngine.animation.start()
Expand All @@ -65,7 +65,7 @@ const EmblaCarousel: React.FC<PropType> = (props) => {
const engine = emblaApi.internalEngine()

if (hasMoreToLoadRef.current && engine.dragHandler.pointerDown()) {
const boundsActive = engine.limit.reachedMax(engine.target.get())
const boundsActive = engine.limit.reachedMax(engine.target.value)
engine.scrollBounds.toggleActive(boundsActive)
emblaApi.on('pointerUp', reloadAfterPointerUp)
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ export const IosPickerItem: React.FC<PropType> = (props) => {

emblaApi.on('pointerUp', () => {
const { scrollTo, target, location } = emblaApi.internalEngine()
const diffToTarget = target.get() - location.get()
const diffToTarget = target.value - location.value
const factor = Math.abs(diffToTarget) < WHEEL_ITEM_SIZE / 2.5 ? 10 : 0.1
const distance = diffToTarget * factor
scrollTo.distance(distance, true)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,11 @@ const EmblaCarousel: React.FC<PropType> = (props) => {
const scrollProgress = emblaApi.scrollProgress()

const styles = emblaApi.scrollSnapList().map((scrollSnap, index) => {
if (!emblaApi.slidesInView().includes(index)) return 0
let diffToTarget = scrollSnap - scrollProgress

if (engine.options.loop) {
engine.slideLooper.loopPoints.forEach((loopItem) => {
const target = loopItem.target().get()
const target = loopItem.target()
if (index === loopItem.index && target !== 0) {
const sign = Math.sign(target)
if (sign === -1) diffToTarget = scrollSnap - (1 + scrollProgress)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,11 @@ const EmblaCarousel: React.FC<PropType> = (props) => {
const scrollProgress = emblaApi.scrollProgress()

const styles = emblaApi.scrollSnapList().map((scrollSnap, index) => {
if (!emblaApi.slidesInView().includes(index)) return 0
let diffToTarget = scrollSnap - scrollProgress

if (engine.options.loop) {
engine.slideLooper.loopPoints.forEach((loopItem) => {
const target = loopItem.target().get()
const target = loopItem.target()
if (index === loopItem.index && target !== 0) {
const sign = Math.sign(target)
if (sign === -1) diffToTarget = scrollSnap - (1 + scrollProgress)
Expand Down Expand Up @@ -63,7 +62,7 @@ const EmblaCarousel: React.FC<PropType> = (props) => {
className="embla__parallax__layer"
style={{
...(tweenValues.length && {
transform: `translateX(${tweenValues[index]}%)`,
transform: `translate3d(${tweenValues[index]}%,0px,0px)`,
}),
}}
>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,11 @@ const EmblaCarousel: React.FC<PropType> = (props) => {
const scrollProgress = emblaApi.scrollProgress()

const styles = emblaApi.scrollSnapList().map((scrollSnap, index) => {
if (!emblaApi.slidesInView().includes(index)) return 0
let diffToTarget = scrollSnap - scrollProgress

if (engine.options.loop) {
engine.slideLooper.loopPoints.forEach((loopItem) => {
const target = loopItem.target().get()
const target = loopItem.target()
if (index === loopItem.index && target !== 0) {
const sign = Math.sign(target)
if (sign === -1) diffToTarget = scrollSnap - (1 + scrollProgress)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ export const setupInfiniteScroll = (emblaApi, loadMoreCallback) => {
const deactivateBounds = () => {
if (slideCount === emblaApi.slideNodes().length - 1) return
const engine = emblaApi.internalEngine()
const boundsActive = engine.limit.reachedMax(engine.target.get())
const boundsActive = engine.limit.reachedMax(engine.target.value)
engine.scrollBounds.toggleActive(boundsActive)
}

Expand All @@ -57,7 +57,7 @@ export const setupInfiniteScroll = (emblaApi, loadMoreCallback) => {
Object.assign(newEngine[engineModule], oldEngine[engineModule]),
)

newEngine.translate.to(oldEngine.location)
newEngine.translate.to(oldEngine.location.value)
const { index } = newEngine.scrollTarget.byDistance(0, false)
newEngine.index.set(index)
newEngine.animation.start()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ export const setupInfiniteScroll = (
const deactivateBounds = () => {
if (slideCount === emblaApi.slideNodes().length - 1) return
const engine = emblaApi.internalEngine()
const boundsActive = engine.limit.reachedMax(engine.target.get())
const boundsActive = engine.limit.reachedMax(engine.target.value)
engine.scrollBounds.toggleActive(boundsActive)
}

Expand All @@ -77,7 +77,7 @@ export const setupInfiniteScroll = (
Object.assign(newEngine[engineModule], oldEngine[engineModule]),
)

newEngine.translate.to(oldEngine.location)
newEngine.translate.to(oldEngine.location.value)
const { index } = newEngine.scrollTarget.byDistance(0, false)
newEngine.index.set(index)
newEngine.animation.start()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ export const setupIosPicker = (iosPickerNode, options) => {

emblaApi.on('pointerUp', () => {
const { scrollTo, target, location } = emblaApi.internalEngine()
const diffToTarget = target.get() - location.get()
const diffToTarget = target.value - location.value
const factor = Math.abs(diffToTarget) < WHEEL_ITEM_SIZE / 2.5 ? 10 : 0.1
const distance = diffToTarget * factor
scrollTo.distance(distance, true)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ export const setupIosPicker = (

emblaApi.on('pointerUp', () => {
const { scrollTo, target, location } = emblaApi.internalEngine()
const diffToTarget = target.get() - location.get()
const diffToTarget = target.value - location.value
const factor = Math.abs(diffToTarget) < WHEEL_ITEM_SIZE / 2.5 ? 10 : 0.1
const distance = diffToTarget * factor
scrollTo.distance(distance, true)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ const calculateTweenValuesOpacity = (emblaApi) => {

if (engine.options.loop) {
engine.slideLooper.loopPoints.forEach((loopItem) => {
const target = loopItem.target().get()
const target = loopItem.target()
if (index === loopItem.index && target !== 0) {
const sign = Math.sign(target)
if (sign === -1) diffToTarget = scrollSnap - (1 + scrollProgress)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ const calculateTweenValuesOpacity = (emblaApi: EmblaCarouselType): number[] => {

if (engine.options.loop) {
engine.slideLooper.loopPoints.forEach((loopItem) => {
const target = loopItem.target().get()
const target = loopItem.target()
if (index === loopItem.index && target !== 0) {
const sign = Math.sign(target)
if (sign === -1) diffToTarget = scrollSnap - (1 + scrollProgress)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ const calculateTweenValuesParallax = (emblaApi) => {

if (engine.options.loop) {
engine.slideLooper.loopPoints.forEach((loopItem) => {
const target = loopItem.target().get()
const target = loopItem.target()
if (index === loopItem.index && target !== 0) {
const sign = Math.sign(target)
if (sign === -1) diffToTarget = scrollSnap - (1 + scrollProgress)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ const calculateTweenValuesParallax = (

if (engine.options.loop) {
engine.slideLooper.loopPoints.forEach((loopItem) => {
const target = loopItem.target().get()
const target = loopItem.target()
if (index === loopItem.index && target !== 0) {
const sign = Math.sign(target)
if (sign === -1) diffToTarget = scrollSnap - (1 + scrollProgress)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ const calculateTweenValuesScale = (emblaApi) => {

if (engine.options.loop) {
engine.slideLooper.loopPoints.forEach((loopItem) => {
const target = loopItem.target().get()
const target = loopItem.target()
if (index === loopItem.index && target !== 0) {
const sign = Math.sign(target)
if (sign === -1) diffToTarget = scrollSnap - (1 + scrollProgress)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ const calculateTweenValuesScale = (emblaApi: EmblaCarouselType): number[] => {

if (engine.options.loop) {
engine.slideLooper.loopPoints.forEach((loopItem) => {
const target = loopItem.target().get()
const target = loopItem.target()
if (index === loopItem.index && target !== 0) {
const sign = Math.sign(target)
if (sign === -1) diffToTarget = scrollSnap - (1 + scrollProgress)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ export const setupInfiniteScroll = (
const deactivateBounds = () => {
if (slideCount === emblaApi.slideNodes().length - 1) return
const engine = emblaApi.internalEngine()
const boundsActive = engine.limit.reachedMax(engine.target.get())
const boundsActive = engine.limit.reachedMax(engine.target.value)
engine.scrollBounds.toggleActive(boundsActive)
}

Expand All @@ -77,7 +77,7 @@ export const setupInfiniteScroll = (
Object.assign(newEngine[engineModule], oldEngine[engineModule]),
)

newEngine.translate.to(oldEngine.location)
newEngine.translate.to(oldEngine.location.value)
const { index } = newEngine.scrollTarget.byDistance(0, false)
newEngine.index.set(index)
newEngine.animation.start()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ export const setupIosPicker = (

emblaApi.on('pointerUp', () => {
const { scrollTo, target, location } = emblaApi.internalEngine()
const diffToTarget = target.get() - location.get()
const diffToTarget = target.value - location.value
const factor = Math.abs(diffToTarget) < WHEEL_ITEM_SIZE / 2.5 ? 10 : 0.1
const distance = diffToTarget * factor
scrollTo.distance(distance, true)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ const calculateTweenValuesOpacity = (emblaApi: EmblaCarouselType): number[] => {

if (engine.options.loop) {
engine.slideLooper.loopPoints.forEach((loopItem) => {
const target = loopItem.target().get()
const target = loopItem.target()
if (index === loopItem.index && target !== 0) {
const sign = Math.sign(target)
if (sign === -1) diffToTarget = scrollSnap - (1 + scrollProgress)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ const calculateTweenValuesParallax = (

if (engine.options.loop) {
engine.slideLooper.loopPoints.forEach((loopItem) => {
const target = loopItem.target().get()
const target = loopItem.target()
if (index === loopItem.index && target !== 0) {
const sign = Math.sign(target)
if (sign === -1) diffToTarget = scrollSnap - (1 + scrollProgress)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ const calculateTweenValuesScale = (emblaApi: EmblaCarouselType): number[] => {

if (engine.options.loop) {
engine.slideLooper.loopPoints.forEach((loopItem) => {
const target = loopItem.target().get()
const target = loopItem.target()
if (index === loopItem.index && target !== 0) {
const sign = Math.sign(target)
if (sign === -1) diffToTarget = scrollSnap - (1 + scrollProgress)
Expand Down
Loading

0 comments on commit 85a6458

Please sign in to comment.