@lynx-example/lynx-ui-swiper 0.0.4 → 0.0.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (66) hide show
  1. package/BasicDynamic/index.tsx +66 -74
  2. package/BasicUpdateSize/index.tsx +65 -75
  3. package/Bounces/index.tsx +71 -55
  4. package/Bounces/styles.css +36 -27
  5. package/CHANGELOG.md +9 -0
  6. package/Common/Demo/styles.css +113 -0
  7. package/Custom/index.tsx +43 -41
  8. package/CustomScale/index.tsx +44 -42
  9. package/DifferentHeight/Button.tsx +1 -29
  10. package/Direction/index.tsx +99 -105
  11. package/EmptyDataBug/index.tsx +2 -1
  12. package/EmptyDataBug/styles.css +19 -12
  13. package/Indicator/index.tsx +56 -50
  14. package/Lazy/index.tsx +69 -65
  15. package/Loop/index.tsx +45 -42
  16. package/RTL/Button.tsx +1 -29
  17. package/RTL/index.tsx +74 -83
  18. package/RTLCustom/index.tsx +45 -43
  19. package/RTLLoop/Button.tsx +1 -29
  20. package/RTLLoop/index.tsx +57 -66
  21. package/RTLLoopLynxRTL/Button.tsx +1 -29
  22. package/RTLLoopLynxRTL/index.tsx +57 -66
  23. package/WithGap/Button.tsx +1 -29
  24. package/WithGap/index.tsx +57 -68
  25. package/dist/SwiperBasicDynamic.lynx.bundle +0 -0
  26. package/dist/SwiperBasicDynamic.web.bundle +1 -1
  27. package/dist/SwiperBasicUpdateSize.lynx.bundle +0 -0
  28. package/dist/SwiperBasicUpdateSize.web.bundle +1 -1
  29. package/dist/SwiperBounces.lynx.bundle +0 -0
  30. package/dist/SwiperBounces.web.bundle +1 -1
  31. package/dist/SwiperCustom.lynx.bundle +0 -0
  32. package/dist/SwiperCustom.web.bundle +1 -1
  33. package/dist/SwiperCustomScale.lynx.bundle +0 -0
  34. package/dist/SwiperCustomScale.web.bundle +1 -1
  35. package/dist/SwiperEmptyDataBug.lynx.bundle +0 -0
  36. package/dist/SwiperEmptyDataBug.web.bundle +1 -1
  37. package/dist/SwiperIndicator.lynx.bundle +0 -0
  38. package/dist/SwiperIndicator.web.bundle +1 -1
  39. package/dist/SwiperLazy.lynx.bundle +0 -0
  40. package/dist/SwiperLazy.web.bundle +1 -1
  41. package/dist/SwiperLoop.lynx.bundle +0 -0
  42. package/dist/SwiperLoop.web.bundle +1 -1
  43. package/dist/SwiperRTL.lynx.bundle +0 -0
  44. package/dist/SwiperRTL.web.bundle +1 -1
  45. package/dist/SwiperRTLCustom.lynx.bundle +0 -0
  46. package/dist/SwiperRTLCustom.web.bundle +1 -1
  47. package/dist/SwiperRTLLoop.lynx.bundle +0 -0
  48. package/dist/SwiperRTLLoop.web.bundle +1 -1
  49. package/dist/SwiperRTLLynxRTL.lynx.bundle +0 -0
  50. package/dist/SwiperRTLLynxRTL.web.bundle +1 -1
  51. package/dist/SwiperWithGap.lynx.bundle +0 -0
  52. package/dist/SwiperWithGap.web.bundle +1 -1
  53. package/package.json +2 -2
  54. package/BasicDynamic/styles.css +0 -47
  55. package/BasicUpdateSize/styles.css +0 -47
  56. package/Custom/styles.css +0 -47
  57. package/CustomScale/styles.css +0 -41
  58. package/Direction/styles.css +0 -41
  59. package/Indicator/styles.css +0 -41
  60. package/Lazy/styles.css +0 -41
  61. package/Loop/styles.css +0 -41
  62. package/RTL/styles.css +0 -41
  63. package/RTLCustom/styles.css +0 -41
  64. package/RTLLoop/styles.css +0 -41
  65. package/RTLLoopLynxRTL/styles.css +0 -41
  66. package/WithGap/styles.css +0 -47
@@ -2,63 +2,69 @@
2
2
  // Licensed under the Apache License Version 2.0 that can be found in the
3
3
  // LICENSE file in the root directory of this source tree.
4
4
 
5
- import { root } from '@lynx-js/react'
5
+ import { root, useState } from '@lynx-js/react'
6
6
 
7
7
  import { Swiper, SwiperItem } from '@lynx-js/lynx-ui'
8
8
 
9
- import './styles.css'
9
+ import { Card } from '../Common/Card'
10
+ import { Indicator } from '../Common/Indicator'
10
11
 
11
- const colorsArr: string[] = ['red', 'green', 'yellow', 'purple']
12
+ import '../Common/Demo/styles.css'
13
+
14
+ const itemArr: number[] = [1, 2, 3, 4]
12
15
 
13
16
  function SwiperEntry() {
17
+ const [currentIndex, setCurrentIndex] = useState(0)
18
+
14
19
  return (
15
- <Swiper
16
- data={colorsArr}
17
- itemWidth={375}
18
- itemHeight={200}
19
- loop={false}
20
- duration={500}
21
- initialIndex={0}
22
- mode='normal'
23
- bounceConfig={{
24
- enable: true,
25
- startBounceItemWidth: 100,
26
- startBounceItem: (
27
- <view>
28
- <text>123</text>
29
- </view>
30
- ),
31
- }}
32
- onChange={i => {
33
- console.log('change', i)
34
- }}
35
- >
36
- {({ item, index, realIndex }) => (
37
- <SwiperItem index={index} key={realIndex} realIndex={realIndex}>
38
- <view
39
- class='block-view'
40
- style={{
41
- width: '100%',
42
- height: '100%',
43
- backgroundColor: item,
44
- display: 'flex',
45
- justifyContent: 'center',
46
- alignItems: 'center',
47
- }}
48
- >
49
- <view
50
- style={{
51
- backgroundColor: 'white',
52
- width: '4px',
53
- height: '4px',
54
- }}
55
- >
56
- </view>
57
- </view>
58
- <text class='image-text'>Number.{index}</text>
59
- </SwiperItem>
60
- )}
61
- </Swiper>
20
+ <view className='demo-container lunaris-dark'>
21
+ <view className='top-area' />
22
+ <view className='content-area'>
23
+ <Swiper
24
+ data={itemArr}
25
+ itemWidth={300}
26
+ itemHeight={250}
27
+ containerWidth={lynx.__globalProps.screenWidth - 32
28
+ || SystemInfo.pixelWidth / SystemInfo.pixelRatio - 32}
29
+ loop={false}
30
+ duration={500}
31
+ initialIndex={0}
32
+ mode='normal'
33
+ modeConfig={{
34
+ align: 'center',
35
+ spaceBetween: 16,
36
+ }}
37
+ bounceConfig={{
38
+ enable: true,
39
+ startBounceItemWidth: 100,
40
+ startBounceItem: (
41
+ <view className='bounce-item'>
42
+ <text className='bounce-item-text'>Start</text>
43
+ </view>
44
+ ),
45
+ }}
46
+ onChange={setCurrentIndex}
47
+ style={{
48
+ overflow: 'visible',
49
+ }}
50
+ >
51
+ {({ index, realIndex }) => (
52
+ <SwiperItem index={index} key={realIndex} realIndex={realIndex}>
53
+ <Card
54
+ index={realIndex}
55
+ style={{
56
+ height: '250px',
57
+ }}
58
+ />
59
+ </SwiperItem>
60
+ )}
61
+ </Swiper>
62
+ <Indicator
63
+ current={currentIndex}
64
+ count={itemArr.length}
65
+ />
66
+ </view>
67
+ </view>
62
68
  )
63
69
  }
64
70
 
package/Lazy/index.tsx CHANGED
@@ -2,79 +2,83 @@
2
2
  // Licensed under the Apache License Version 2.0 that can be found in the
3
3
  // LICENSE file in the root directory of this source tree.
4
4
 
5
- import { root } from '@lynx-js/react'
5
+ import { root, useState } from '@lynx-js/react'
6
6
 
7
7
  import { LazyComponent, Swiper, SwiperItem } from '@lynx-js/lynx-ui'
8
8
 
9
- import './styles.css'
9
+ import { Card } from '../Common/Card'
10
+ import { Indicator } from '../Common/Indicator'
10
11
 
11
- const colorsArr: string[] = [
12
- 'red',
13
- 'green',
14
- 'yellow',
15
- 'purple',
16
- 'lightblue',
17
- 'lightgreen',
18
- 'lightyellow',
19
- ]
12
+ import '../Common/Demo/styles.css'
13
+
14
+ const itemArr: number[] = [1, 2, 3, 4, 5, 6, 7]
20
15
 
21
16
  function SwiperEntry() {
17
+ const [currentIndex, setCurrentIndex] = useState(0)
18
+
22
19
  return (
23
- <Swiper
24
- data={colorsArr}
25
- itemWidth={250}
26
- itemHeight={200}
27
- loop={false}
28
- duration={500}
29
- initialIndex={0}
30
- mode='normal'
31
- modeConfig={{
32
- align: 'start',
33
- }}
34
- bounceConfig={{
35
- enable: true,
36
- startBounceItemWidth: 0,
37
- endBounceItem: (
38
- <view style='display: linear; linear-orientation: vertical; height: 100%; width: 30px; border: 1px solid #000;'>
39
- <text style='color: #000'>Show More</text>
40
- </view>
41
- ),
42
- onEndBounceItemBounce: ({ type }) => {
43
- console.log('onBounce result', type)
44
- },
45
- }}
46
- >
47
- {({ item, index, realIndex }) => (
48
- <SwiperItem index={index} key={realIndex} realIndex={realIndex}>
49
- <LazyComponent
50
- scene='scene'
51
- pid={`pid_${realIndex}`}
52
- estimatedStyle={{ width: '100%', height: '100%' }}
53
- >
54
- <view
55
- class='block-view'
56
- style={{
57
- width: '100%',
58
- height: '100%',
59
- backgroundColor: item,
60
- display: 'flex',
61
- justifyContent: 'center',
62
- alignItems: 'center',
63
- }}
64
- >
65
- <view
66
- style={{
67
- backgroundColor: 'white',
68
- width: '4px',
69
- height: '4px',
70
- }}
71
- >
20
+ <view className='demo-container lunaris-dark'>
21
+ <view className='top-area' />
22
+ <view className='content-area'>
23
+ <Swiper
24
+ data={itemArr}
25
+ itemWidth={250}
26
+ itemHeight={250}
27
+ containerWidth={lynx.__globalProps.screenWidth - 32
28
+ || SystemInfo.pixelWidth / SystemInfo.pixelRatio - 32}
29
+ loop={false}
30
+ duration={500}
31
+ initialIndex={0}
32
+ mode='normal'
33
+ modeConfig={{
34
+ align: 'start',
35
+ spaceBetween: 16,
36
+ }}
37
+ bounceConfig={{
38
+ enable: true,
39
+ startBounceItemWidth: 0,
40
+ endBounceItem: (
41
+ <view className='bounce-item'>
42
+ <text className='bounce-item-text'>Show More</text>
72
43
  </view>
73
- </view>
74
- </LazyComponent>
75
- </SwiperItem>
76
- )}
77
- </Swiper>
44
+ ),
45
+ onEndBounceItemBounce: ({ type }) => {
46
+ console.log('onBounce result', type)
47
+ },
48
+ }}
49
+ onChange={setCurrentIndex}
50
+ style={{
51
+ overflow: 'visible',
52
+ }}
53
+ >
54
+ {({ index, realIndex }) => (
55
+ <SwiperItem index={index} key={realIndex} realIndex={realIndex}>
56
+ <LazyComponent
57
+ scene='scene'
58
+ pid={`pid_${realIndex}`}
59
+ estimatedStyle={{ width: '100%', height: '100%' }}
60
+ >
61
+ <Card
62
+ index={realIndex}
63
+ style={{
64
+ height: '250px',
65
+ }}
66
+ />
67
+ </LazyComponent>
68
+ </SwiperItem>
69
+ )}
70
+ </Swiper>
71
+ <Indicator
72
+ current={currentIndex}
73
+ count={itemArr.length}
74
+ />
75
+ </view>
76
+ <view className='demo-status'>
77
+ <text className='demo-status-text'>
78
+ Each slide body is mounted through LazyComponent.
79
+ </text>
80
+ </view>
81
+ </view>
78
82
  )
79
83
  }
80
84
 
package/Loop/index.tsx CHANGED
@@ -6,9 +6,12 @@ import { root, useState } from '@lynx-js/react'
6
6
 
7
7
  import { Swiper, SwiperItem } from '@lynx-js/lynx-ui'
8
8
 
9
- import './styles.css'
9
+ import { Card } from '../Common/Card'
10
+ import { Indicator } from '../Common/Indicator'
10
11
 
11
- const colorsArr: string[] = ['red', 'green', 'yellow', 'purple']
12
+ import '../Common/Demo/styles.css'
13
+
14
+ const itemArr: number[] = [1, 2, 3, 4]
12
15
 
13
16
  function SwiperEntry() {
14
17
  const [currentIndex, setCurrentIndex] = useState(0)
@@ -25,48 +28,48 @@ function SwiperEntry() {
25
28
  containWidth,
26
29
  )
27
30
  return (
28
- <view>
29
- <Swiper
30
- data={colorsArr}
31
- itemWidth={itemWidth + SwiperItemGap}
32
- itemHeight={219.92727272727276}
33
- containerWidth={containWidth}
34
- loop={true}
35
- duration={500}
36
- initialIndex={0}
37
- mode='normal'
38
- autoPlay={true}
39
- onChange={setCurrentIndex}
40
- experimentalHorizontalSwipeOnly={true}
41
- >
42
- {({ item, index, realIndex }) => (
43
- <SwiperItem index={index} key={realIndex} realIndex={realIndex}>
44
- <view
45
- class='block-view'
46
- style={{
47
- width: '100%',
48
- height: '100%',
49
- backgroundColor: item,
50
- display: 'flex',
51
- justifyContent: 'center',
52
- alignItems: 'center',
53
- }}
54
- >
55
- <view
31
+ <view className='demo-container lunaris-dark'>
32
+ <view className='top-area' />
33
+ <view className='content-area'>
34
+ <Swiper
35
+ data={itemArr}
36
+ itemWidth={itemWidth + SwiperItemGap}
37
+ itemHeight={250}
38
+ containerWidth={containWidth}
39
+ loop={true}
40
+ duration={500}
41
+ initialIndex={0}
42
+ mode='normal'
43
+ modeConfig={{
44
+ spaceBetween: SwiperItemGap,
45
+ }}
46
+ autoPlay={true}
47
+ onChange={setCurrentIndex}
48
+ experimentalHorizontalSwipeOnly={true}
49
+ style={{
50
+ overflow: 'visible',
51
+ }}
52
+ >
53
+ {({ index, realIndex }) => (
54
+ <SwiperItem index={index} key={realIndex} realIndex={realIndex}>
55
+ <Card
56
+ index={realIndex}
56
57
  style={{
57
- backgroundColor: 'white',
58
- width: '4px',
59
- height: '4px',
58
+ height: '250px',
60
59
  }}
61
- >
62
- </view>
63
- </view>
64
- <text class='image-text'>Number.{index}</text>
65
- </SwiperItem>
66
- )}
67
- </Swiper>
68
- <view>
69
- <text>currentIndex: {currentIndex}</text>
60
+ />
61
+ </SwiperItem>
62
+ )}
63
+ </Swiper>
64
+ <Indicator
65
+ current={currentIndex}
66
+ count={itemArr.length}
67
+ />
68
+ </view>
69
+ <view className='demo-status'>
70
+ <text className='demo-status-text'>
71
+ Loop mode keeps autoplay continuous across the boundary.
72
+ </text>
70
73
  </view>
71
74
  </view>
72
75
  )
package/RTL/Button.tsx CHANGED
@@ -2,32 +2,4 @@
2
2
  // Licensed under the Apache License Version 2.0 that can be found in the
3
3
  // LICENSE file in the root directory of this source tree.
4
4
 
5
- import './styles.css'
6
- import { Button as ButtonInner } from '@lynx-js/lynx-ui'
7
-
8
- const ButtonStyle = {
9
- border: '1px solid',
10
- 'border-radius': '4px',
11
- width: '150px',
12
- 'background-color': 'red',
13
- margin: '4px 8px',
14
- padding: '4px 8px',
15
- }
16
-
17
- const ButtonTextStyle = {
18
- color: 'white',
19
- }
20
-
21
- export function Button(props: {
22
- onClick: () => void
23
- text: string
24
- }) {
25
- return (
26
- <ButtonInner
27
- style={ButtonStyle}
28
- onClick={props.onClick}
29
- >
30
- <text style={ButtonTextStyle}>{props.text}</text>
31
- </ButtonInner>
32
- )
33
- }
5
+ export { Button } from '../Common/Button'
package/RTL/index.tsx CHANGED
@@ -7,19 +7,13 @@ import { root, useRef, useState } from '@lynx-js/react'
7
7
  import { Swiper, SwiperItem } from '@lynx-js/lynx-ui'
8
8
  import type { SwiperRef } from '@lynx-js/lynx-ui'
9
9
 
10
- import './styles.css'
10
+ import { Button } from '../Common/Button'
11
+ import { Card } from '../Common/Card'
12
+ import { Indicator } from '../Common/Indicator'
11
13
 
12
- import { Button } from './Button'
14
+ import '../Common/Demo/styles.css'
13
15
 
14
- const colorsArr: string[] = [
15
- 'red',
16
- 'green',
17
- 'yellow',
18
- 'purple',
19
- 'lightblue',
20
- 'lightgreen',
21
- 'lightyellow',
22
- ]
16
+ const itemArr: number[] = [1, 2, 3, 4, 5, 6, 7]
23
17
 
24
18
  const itemWidths = [250, 350, 400]
25
19
  const alignArr: ['start', 'center', 'end'] = ['start', 'center', 'end']
@@ -31,98 +25,95 @@ function SwiperEntry(): JSX.Element {
31
25
  const swiperRef = useRef<SwiperRef>(null)
32
26
 
33
27
  return (
34
- <view id='container'>
35
- <Swiper
36
- ref={swiperRef}
37
- data={colorsArr}
38
- itemWidth={itemWidths[itemWidthsIndex] ?? 0}
39
- itemHeight={200}
40
- duration={500}
41
- initialIndex={0}
42
- onChange={setCurrentIndex}
43
- mode='normal'
44
- modeConfig={{
45
- align: alignArr[alignIndex] ?? 'start',
46
- spaceBetween: 8,
47
- }}
48
- RTL={true}
49
- bounceConfig={{
50
- enable: true,
51
- startBounceItemWidth: 100,
52
- endBounceItemWidth: 100,
53
- startBounceItem: (
54
- <view style='display: linear; linear-orientation: vertical; height: 100%; width: 30px; border: 1px solid #000;'>
55
- <text style='color: #000'>Start Show More</text>
56
- </view>
57
- ),
58
- endBounceItem: (
59
- <view style='display: linear; linear-orientation: vertical; height: 100%; width: 30px; border: 1px solid #000;'>
60
- <text style='color: #000'>Show More</text>
61
- </view>
62
- ),
63
- onEndBounceItemBounce: ({ type }) => {
64
- console.log('onBounce result', type)
65
- },
66
- }}
67
- >
68
- {({ item, index, realIndex }) => (
69
- <SwiperItem index={index} key={realIndex} realIndex={realIndex}>
70
- <view
71
- class='block-view'
72
- style={{
73
- width: '100%',
74
- height: '100%',
75
- backgroundColor: item,
76
- display: 'flex',
77
- justifyContent: 'center',
78
- alignItems: 'center',
79
- }}
80
- >
81
- <view
28
+ <view className='demo-container lunaris-dark'>
29
+ <view className='top-area' />
30
+ <view className='content-area'>
31
+ <Swiper
32
+ ref={swiperRef}
33
+ data={itemArr}
34
+ itemWidth={itemWidths[itemWidthsIndex] ?? 0}
35
+ itemHeight={250}
36
+ containerWidth={lynx.__globalProps.screenWidth - 32
37
+ || SystemInfo.pixelWidth / SystemInfo.pixelRatio - 32}
38
+ duration={500}
39
+ initialIndex={0}
40
+ onChange={setCurrentIndex}
41
+ mode='normal'
42
+ modeConfig={{
43
+ align: alignArr[alignIndex] ?? 'start',
44
+ spaceBetween: 16,
45
+ }}
46
+ RTL={true}
47
+ style={{
48
+ overflow: 'visible',
49
+ }}
50
+ bounceConfig={{
51
+ enable: true,
52
+ startBounceItemWidth: 100,
53
+ endBounceItemWidth: 100,
54
+ startBounceItem: (
55
+ <view className='bounce-item'>
56
+ <text className='bounce-item-text'>Start</text>
57
+ </view>
58
+ ),
59
+ endBounceItem: (
60
+ <view className='bounce-item'>
61
+ <text className='bounce-item-text'>End</text>
62
+ </view>
63
+ ),
64
+ onEndBounceItemBounce: ({ type }) => {
65
+ console.log('onBounce result', type)
66
+ },
67
+ }}
68
+ >
69
+ {({ index, realIndex }) => (
70
+ <SwiperItem index={index} key={realIndex} realIndex={realIndex}>
71
+ <Card
72
+ index={realIndex}
82
73
  style={{
83
- backgroundColor: 'white',
84
- width: '4px',
85
- height: '4px',
74
+ height: '250px',
86
75
  }}
87
- >
88
- </view>
89
- </view>
90
- <text class='image-text'>Number.{index}</text>
91
- </SwiperItem>
92
- )}
93
- </Swiper>
94
- <view class='operation'>
95
- <view class='block'>
96
- <text>Current Index: {currentIndex}</text>
97
- </view>
76
+ />
77
+ </SwiperItem>
78
+ )}
79
+ </Swiper>
80
+ <Indicator
81
+ current={currentIndex}
82
+ count={itemArr.length}
83
+ />
84
+ </view>
85
+ <view className='operation'>
98
86
  <Button
99
87
  onClick={() => {
100
88
  swiperRef.current?.swipePrev()
101
89
  }}
90
+ className='expand'
102
91
  text='SwipePrev'
103
- >
104
- </Button>
92
+ />
105
93
  <Button
106
94
  onClick={() => {
107
95
  swiperRef.current?.swipeNext()
108
96
  }}
97
+ className='expand'
98
+ type='primary'
109
99
  text='SwipeNext'
110
- >
111
- </Button>
100
+ />
101
+ </view>
102
+ <view className='sub-operation'>
112
103
  <Button
113
104
  onClick={() => {
114
105
  setItemWidthsIndex(prev => (prev + 1) % itemWidths.length)
115
106
  }}
116
- text={`itemWidth: ${itemWidths[itemWidthsIndex]}`}
117
- >
118
- </Button>
107
+ text='Change Item Width'
108
+ subText={`ItemWidth: ${itemWidths[itemWidthsIndex]}`}
109
+ />
119
110
  <Button
120
111
  onClick={() => {
121
112
  setAlignIndex(prev => (prev + 1) % itemWidths.length)
122
113
  }}
123
- text={`alignType: ${alignArr[alignIndex]}`}
124
- >
125
- </Button>
114
+ text='Change Align Type'
115
+ subText={`AlignType: ${alignArr[alignIndex]}`}
116
+ />
126
117
  </view>
127
118
  </view>
128
119
  )