import React, { useRef, useEffect } from 'react' import BScroll from '@better-scroll/core' import NestedScroll from '@better-scroll/nested-scroll' BScroll.use(NestedScroll) const outerOpenData = [ '----Outer Start----', '๐๐ป outer scroll ๐๐ป ', '๐ ๐ค ๐ ๐คจ ๐ ๐ ', '๐๐ป outer scroll ๐๐ป ', ] const outerCloseData = [ '๐๐ป outer scroll ๐๐ป ', '๐ ๐ค ๐ ๐คจ ๐ ๐ ', '๐๐ป outer scroll ๐๐ป ', '๐ ๐ ๐ ๐ค ๐ฒ ๐ฒ ', '๐ ๐ค ๐ ๐คจ ๐ ๐ ', '๐๐ป outer scroll ๐๐ป ', '----Outer End----', ] const middleOpenData = [ '----Middle Start----', '๐๐ป middle scroll ๐๐ป ', '๐ฃ ๐ฃ ๐ฃ ๐ฃ ๐ฃ ๐ฃ ', ] const middleCloseData = [ '๐๐ป middle scroll ๐๐ป ', '๐ค ๐ค ๐ค ๐ค ๐ค ๐ค ', '๐๐ป middle scroll ๐๐ป ', '๐ฆ ๐ฆ ๐ฆ ๐ฆ ๐ฆ ๐ฆ ', '๐๐ป middle scroll ๐๐ป ', '๐ ๐ ๐ ๐ ๐ ๐ ', '๐๐ป middle scroll ๐๐ป ', '๐ ๐ ๐ ๐ ๐ ๐ ', '๐๐ป middle scroll ๐๐ป ', 'โ๐ป โ๐ป โ๐ป โ๐ป โ๐ป โ๐ป ', '----Middle End----', ] const innerData = [ '------Inner Start-----', '๐ ๐ ๐ ๐คฃ ๐ ๐ ', '๐๐ป inner scroll ๐๐ป ', '๐ ๐ค ๐ ๐คจ ๐ ๐ ', '๐๐ป inner scroll ๐๐ป ', '๐ ๐ ๐ ๐ค ๐ฒ ๐ ๐ ', '๐๐ป inner scroll ๐๐ป ', '๐ฃ ๐ฃ ๐ฃ ๐ฃ ๐ฃ ๐ฃ ', '๐๐ป inner scroll ๐๐ป ', '๐ฅ ๐ฅ ๐ฅ ๐ฅ ๐ฅ ๐ฅ ', '๐๐ป inner scroll ๐๐ป ', '๐ค ๐ค ๐ค ๐ค ๐ค ๐ค ', '๐๐ป inner scroll ๐๐ป ', '๐ฆ ๐ฆ ๐ฆ ๐ฆ ๐ฆ ๐ฆ ', '๐๐ป inner scroll ๐๐ป ', '๐ ๐ ๐ ๐ ๐ ๐ ', '๐๐ป inner scroll ๐๐ป ', '๐ ๐ ๐ ๐ ๐ ๐ ', '๐๐ป inner scroll ๐๐ป ', 'โ๐ป โ๐ป โ๐ป โ๐ป โ๐ป โ๐ป ', '-----Inner End-----', ] const handleOuterClick = () => { alert('clicked outer item') } const handleMiddleClick = () => { alert('clicked middle item') } const handleInnerClick = () => { alert('clicked inner item') } const TripleVertical = () => { const outerWrapperRef = useRef(null) const middleWrapperRef = useRef(null) const innerWrapperRef = useRef(null) useEffect(() => { const outerScroll = new BScroll(outerWrapperRef.current, { nestedScroll: { groupId: 'triple-nested-scroll', // groupId is a string or number }, click: true, }) const middleScroll = new BScroll(middleWrapperRef.current, { nestedScroll: { groupId: 'triple-nested-scroll', // groupId is a string or number }, probeType: 2, click: true, }) middleScroll.on('scroll', () => { console.log('middleScroll scroll') }) const innerScroll = new BScroll(innerWrapperRef.current, { // please keep the same groupId as above // all scrolls will be controlled by the same nestedScroll instance nestedScroll: { groupId: 'triple-nested-scroll', }, probeType: 2, click: true, }) innerScroll.on('scroll', () => { console.log('innerScroll scroll') }) innerScroll.on('scrollEnd', () => { console.log('innerScroll scrollEnd') }) return () => { outerScroll.destroy() middleScroll.destroy() innerScroll.destroy() } }, []) return (