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

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 (78) hide show
  1. package/Basic/index.tsx +3 -3
  2. package/Basic/styles.css +1 -1
  3. package/BasicDynamic/index.tsx +66 -74
  4. package/BasicUpdateSize/index.tsx +65 -75
  5. package/Bounces/index.tsx +71 -55
  6. package/Bounces/styles.css +36 -27
  7. package/CHANGELOG.md +18 -0
  8. package/Common/Demo/styles.css +113 -0
  9. package/Custom/index.tsx +43 -41
  10. package/CustomScale/index.tsx +44 -42
  11. package/CustomTinder/index.tsx +2 -2
  12. package/CustomTinder/styles.css +1 -1
  13. package/DifferentHeight/Button.tsx +1 -29
  14. package/DifferentHeight/index.tsx +4 -4
  15. package/DifferentHeight/styles.css +1 -1
  16. package/Direction/index.tsx +97 -105
  17. package/EmptyDataBug/index.tsx +14 -13
  18. package/EmptyDataBug/styles.css +19 -12
  19. package/Indicator/index.tsx +56 -50
  20. package/Lazy/index.tsx +69 -65
  21. package/Loop/index.tsx +45 -42
  22. package/RTL/Button.tsx +1 -29
  23. package/RTL/index.tsx +74 -83
  24. package/RTLCustom/index.tsx +45 -43
  25. package/RTLLoop/Button.tsx +1 -29
  26. package/RTLLoop/index.tsx +57 -66
  27. package/RTLLoopLynxRTL/Button.tsx +1 -29
  28. package/RTLLoopLynxRTL/index.tsx +57 -66
  29. package/WithGap/Button.tsx +1 -29
  30. package/WithGap/index.tsx +57 -68
  31. package/dist/SwiperBasic.lynx.bundle +0 -0
  32. package/dist/SwiperBasic.web.bundle +1 -1
  33. package/dist/SwiperBasicDynamic.lynx.bundle +0 -0
  34. package/dist/SwiperBasicDynamic.web.bundle +1 -1
  35. package/dist/SwiperBasicUpdateSize.lynx.bundle +0 -0
  36. package/dist/SwiperBasicUpdateSize.web.bundle +1 -1
  37. package/dist/SwiperBounces.lynx.bundle +0 -0
  38. package/dist/SwiperBounces.web.bundle +1 -1
  39. package/dist/SwiperCustom.lynx.bundle +0 -0
  40. package/dist/SwiperCustom.web.bundle +1 -1
  41. package/dist/SwiperCustomScale.lynx.bundle +0 -0
  42. package/dist/SwiperCustomScale.web.bundle +1 -1
  43. package/dist/SwiperCustomTinder.lynx.bundle +0 -0
  44. package/dist/SwiperCustomTinder.web.bundle +1 -1
  45. package/dist/SwiperDifferentHeight.lynx.bundle +0 -0
  46. package/dist/SwiperDifferentHeight.web.bundle +1 -1
  47. package/dist/SwiperEmptyDataBug.lynx.bundle +0 -0
  48. package/dist/SwiperEmptyDataBug.web.bundle +1 -1
  49. package/dist/SwiperIndicator.lynx.bundle +0 -0
  50. package/dist/SwiperIndicator.web.bundle +1 -1
  51. package/dist/SwiperLazy.lynx.bundle +0 -0
  52. package/dist/SwiperLazy.web.bundle +1 -1
  53. package/dist/SwiperLoop.lynx.bundle +0 -0
  54. package/dist/SwiperLoop.web.bundle +1 -1
  55. package/dist/SwiperRTL.lynx.bundle +0 -0
  56. package/dist/SwiperRTL.web.bundle +1 -1
  57. package/dist/SwiperRTLCustom.lynx.bundle +0 -0
  58. package/dist/SwiperRTLCustom.web.bundle +1 -1
  59. package/dist/SwiperRTLLoop.lynx.bundle +0 -0
  60. package/dist/SwiperRTLLoop.web.bundle +1 -1
  61. package/dist/SwiperRTLLynxRTL.lynx.bundle +0 -0
  62. package/dist/SwiperRTLLynxRTL.web.bundle +1 -1
  63. package/dist/SwiperWithGap.lynx.bundle +0 -0
  64. package/dist/SwiperWithGap.web.bundle +1 -1
  65. package/package.json +6 -6
  66. package/BasicDynamic/styles.css +0 -47
  67. package/BasicUpdateSize/styles.css +0 -47
  68. package/Custom/styles.css +0 -47
  69. package/CustomScale/styles.css +0 -41
  70. package/Direction/styles.css +0 -41
  71. package/Indicator/styles.css +0 -41
  72. package/Lazy/styles.css +0 -41
  73. package/Loop/styles.css +0 -41
  74. package/RTL/styles.css +0 -41
  75. package/RTLCustom/styles.css +0 -41
  76. package/RTLLoop/styles.css +0 -41
  77. package/RTLLoopLynxRTL/styles.css +0 -41
  78. package/WithGap/styles.css +0 -47
@@ -0,0 +1,113 @@
1
+ @import "@lynx-js/luna-styles/index.css";
2
+
3
+ .demo-container {
4
+ background-color: var(--canvas);
5
+ display: flex;
6
+ width: 100%;
7
+ height: 100%;
8
+ flex-direction: column;
9
+ justify-content: center;
10
+ }
11
+
12
+ .demo-scroll-container {
13
+ background-color: var(--canvas);
14
+ width: 100%;
15
+ height: 100%;
16
+ }
17
+
18
+ .expand {
19
+ flex: 1;
20
+ }
21
+
22
+ .top-area {
23
+ height: 54px;
24
+ width: 100%;
25
+ }
26
+
27
+ .content-area {
28
+ display: flex;
29
+ background: linear-gradient(
30
+ 0deg,
31
+ var(--gradient-a),
32
+ var(--gradient-b)
33
+ );
34
+ padding-top: 96px;
35
+ flex-direction: column;
36
+ justify-content: center;
37
+ align-items: center;
38
+ row-gap: 24px;
39
+ padding-bottom: 12px;
40
+ }
41
+
42
+ .content-area--compact {
43
+ padding-top: 48px;
44
+ }
45
+
46
+ .operation {
47
+ display: flex;
48
+ flex-direction: row;
49
+ gap: 16px;
50
+ padding: 32px 16px;
51
+ }
52
+
53
+ .sub-operation {
54
+ display: flex;
55
+ flex: 1;
56
+ flex-direction: column;
57
+ gap: 8px;
58
+ padding: 0 16px 72px 16px;
59
+ }
60
+
61
+ .demo-status {
62
+ display: flex;
63
+ flex-direction: column;
64
+ gap: 4px;
65
+ padding: 12px 16px;
66
+ margin: 0 16px;
67
+ border-radius: 8px;
68
+ background-color: var(--neutral-ambient);
69
+ }
70
+
71
+ .demo-status-text {
72
+ color: var(--content-muted);
73
+ font-size: 12px;
74
+ line-height: 16px;
75
+ }
76
+
77
+ .demo-section {
78
+ padding: 0 16px 32px;
79
+ }
80
+
81
+ .demo-section-title {
82
+ color: var(--content);
83
+ font-size: 16px;
84
+ font-weight: 600;
85
+ line-height: 20px;
86
+ margin-bottom: 8px;
87
+ }
88
+
89
+ .demo-section-description {
90
+ color: var(--content-muted);
91
+ font-size: 12px;
92
+ line-height: 16px;
93
+ margin-bottom: 16px;
94
+ }
95
+
96
+ .bounce-item {
97
+ display: flex;
98
+ height: 100%;
99
+ width: 72px;
100
+ align-items: center;
101
+ justify-content: center;
102
+ border-width: 1px;
103
+ border-color: var(--line);
104
+ border-radius: 8px;
105
+ background-color: var(--neutral-ambient);
106
+ }
107
+
108
+ .bounce-item-text {
109
+ color: var(--content-muted);
110
+ font-size: 12px;
111
+ line-height: 16px;
112
+ text-align: center;
113
+ }
package/Custom/index.tsx CHANGED
@@ -2,7 +2,7 @@
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, useRef } from '@lynx-js/react'
5
+ import { root, useRef, useState } from '@lynx-js/react'
6
6
 
7
7
  import {
8
8
  Swiper,
@@ -12,9 +12,12 @@ import {
12
12
  } from '@lynx-js/lynx-ui'
13
13
  import type { SwiperRef } from '@lynx-js/lynx-ui'
14
14
 
15
- import './styles.css'
15
+ import { Card } from '../Common/Card'
16
+ import { Indicator } from '../Common/Indicator'
16
17
 
17
- const colorsArr: string[] = ['red', 'green', 'yellow', 'purple']
18
+ import '../Common/Demo/styles.css'
19
+
20
+ const itemArr: number[] = [1, 2, 3, 4, 5]
18
21
 
19
22
  function customAnimation(value: number, _index: number) {
20
23
  'main thread'
@@ -36,48 +39,47 @@ function customAnimationFirstScreen(value: number, _index: number) {
36
39
 
37
40
  function SwiperEntry(): JSX.Element {
38
41
  const swiperRef = useRef<SwiperRef>(null)
42
+ const [currentIndex, setCurrentIndex] = useState(0)
39
43
 
40
44
  return (
41
- <view id='container'>
42
- <Swiper
43
- ref={swiperRef}
44
- data={colorsArr}
45
- itemWidth={250}
46
- duration={500}
47
- initialIndex={0}
48
- mode='normal'
49
- modeConfig={{
50
- align: 'center',
51
- }}
52
- main-thread:customAnimation={customAnimation}
53
- customAnimationFirstScreen={customAnimationFirstScreen}
54
- >
55
- {({ item, index, realIndex }) => (
56
- <SwiperItem index={index} key={realIndex} realIndex={realIndex}>
57
- <view
58
- class='block-view'
59
- style={{
60
- width: '100%',
61
- height: '250px',
62
- backgroundColor: item,
63
- display: 'flex',
64
- justifyContent: 'center',
65
- alignItems: 'center',
66
- }}
67
- >
68
- <view
45
+ <view className='demo-container lunaris-dark'>
46
+ <view className='top-area' />
47
+ <view className='content-area'>
48
+ <Swiper
49
+ ref={swiperRef}
50
+ data={itemArr}
51
+ itemWidth={250}
52
+ duration={500}
53
+ initialIndex={0}
54
+ mode='normal'
55
+ modeConfig={{
56
+ align: 'center',
57
+ }}
58
+ onChange={setCurrentIndex}
59
+ main-thread:customAnimation={customAnimation}
60
+ customAnimationFirstScreen={customAnimationFirstScreen}
61
+ style={{
62
+ overflow: 'visible',
63
+ }}
64
+ >
65
+ {({ index }) => (
66
+ <SwiperItem>
67
+ <Card
68
+ index={index}
69
69
  style={{
70
- backgroundColor: 'white',
71
- width: '4px',
72
- height: '4px',
70
+ height: '250px',
73
71
  }}
74
- >
75
- </view>
76
- </view>
77
- <text class='image-text'>Number.{index}</text>
78
- </SwiperItem>
79
- )}
80
- </Swiper>
72
+ />
73
+ </SwiperItem>
74
+ )}
75
+ </Swiper>
76
+ <Indicator current={currentIndex} count={itemArr.length} />
77
+ </view>
78
+ <view className='demo-status'>
79
+ <text className='demo-status-text'>
80
+ Custom animation scales each slide around the active item.
81
+ </text>
82
+ </view>
81
83
  </view>
82
84
  )
83
85
  }
@@ -2,7 +2,7 @@
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, useRef } from '@lynx-js/react'
5
+ import { root, useRef, useState } from '@lynx-js/react'
6
6
 
7
7
  import {
8
8
  Swiper,
@@ -12,9 +12,12 @@ import {
12
12
  } from '@lynx-js/lynx-ui'
13
13
  import type { SwiperRef } from '@lynx-js/lynx-ui'
14
14
 
15
- import './styles.css'
15
+ import { Card } from '../Common/Card'
16
+ import { Indicator } from '../Common/Indicator'
16
17
 
17
- const colorsArr: string[] = ['red', 'green', 'yellow', 'purple']
18
+ import '../Common/Demo/styles.css'
19
+
20
+ const itemArr: number[] = [1, 2, 3, 4, 5]
18
21
 
19
22
  const ITEM_WIDTH = 250
20
23
 
@@ -64,49 +67,48 @@ function customAnimationFirstScreen(value: number, _index: number) {
64
67
 
65
68
  function SwiperEntry(): JSX.Element {
66
69
  const swiperRef = useRef<SwiperRef>(null)
70
+ const [currentIndex, setCurrentIndex] = useState(0)
67
71
 
68
72
  return (
69
- <view id='container'>
70
- <Swiper
71
- ref={swiperRef}
72
- data={colorsArr}
73
- itemWidth={ITEM_WIDTH}
74
- itemHeight={200}
75
- duration={500}
76
- initialIndex={0}
77
- mode='custom'
78
- modeConfig={{
79
- align: 'center',
80
- }}
81
- main-thread:customAnimation={customAnimation}
82
- customAnimationFirstScreen={customAnimationFirstScreen}
83
- >
84
- {({ item, index, realIndex }) => (
85
- <SwiperItem index={index} key={realIndex} realIndex={realIndex}>
86
- <view
87
- class='block-view'
88
- style={{
89
- width: '100%',
90
- height: '100%',
91
- backgroundColor: item,
92
- display: 'flex',
93
- justifyContent: 'center',
94
- alignItems: 'center',
95
- }}
96
- >
97
- <view
73
+ <view className='demo-container lunaris-dark'>
74
+ <view className='top-area' />
75
+ <view className='content-area'>
76
+ <Swiper
77
+ ref={swiperRef}
78
+ data={itemArr}
79
+ itemWidth={ITEM_WIDTH}
80
+ itemHeight={250}
81
+ duration={500}
82
+ initialIndex={0}
83
+ mode='custom'
84
+ modeConfig={{
85
+ align: 'center',
86
+ }}
87
+ onChange={setCurrentIndex}
88
+ main-thread:customAnimation={customAnimation}
89
+ customAnimationFirstScreen={customAnimationFirstScreen}
90
+ style={{
91
+ overflow: 'visible',
92
+ }}
93
+ >
94
+ {({ index }) => (
95
+ <SwiperItem>
96
+ <Card
97
+ index={index}
98
98
  style={{
99
- backgroundColor: 'white',
100
- width: '4px',
101
- height: '4px',
99
+ height: '250px',
102
100
  }}
103
- >
104
- </view>
105
- </view>
106
- <text class='image-text'>Number.{index}</text>
107
- </SwiperItem>
108
- )}
109
- </Swiper>
101
+ />
102
+ </SwiperItem>
103
+ )}
104
+ </Swiper>
105
+ <Indicator current={currentIndex} count={itemArr.length} />
106
+ </view>
107
+ <view className='demo-status'>
108
+ <text className='demo-status-text'>
109
+ Custom mode keeps the active slide centered while scaling neighbors.
110
+ </text>
111
+ </view>
110
112
  </view>
111
113
  )
112
114
  }
@@ -85,8 +85,8 @@ function SwiperEntry() {
85
85
  overflow: 'visible',
86
86
  }}
87
87
  >
88
- {({ index, realIndex }) => (
89
- <SwiperItem index={index} key={realIndex} realIndex={realIndex}>
88
+ {({ index }) => (
89
+ <SwiperItem>
90
90
  <view
91
91
  class='block-view'
92
92
  style={{
@@ -11,7 +11,7 @@
11
11
  background: linear-gradient(
12
12
  0deg,
13
13
  var(--gradient-a),
14
- var(--gradient-b),
14
+ var(--gradient-b)
15
15
  );
16
16
  align-items: center;
17
17
  }
@@ -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'
@@ -53,12 +53,12 @@ function SwiperEntry(): JSX.Element {
53
53
  alignItems: 'end',
54
54
  }}
55
55
  >
56
- {({ index, realIndex }) => (
57
- <SwiperItem index={index} key={realIndex} realIndex={realIndex}>
56
+ {({ index }) => (
57
+ <SwiperItem>
58
58
  <Card
59
- index={realIndex}
59
+ index={index}
60
60
  style={{
61
- height: `${itemHeights[realIndex % itemHeights.length]}px`,
61
+ height: `${itemHeights[index % itemHeights.length]}px`,
62
62
  }}
63
63
  />
64
64
  </SwiperItem>
@@ -23,7 +23,7 @@
23
23
  background: linear-gradient(
24
24
  0deg,
25
25
  var(--gradient-a),
26
- var(--gradient-b),
26
+ var(--gradient-b)
27
27
  );
28
28
  padding-top: 96px;
29
29
  flex-direction: column;
@@ -6,118 +6,110 @@ import { root } 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
10
 
11
- const colorsArr: string[] = ['red', 'green', 'yellow', 'purple']
11
+ import '../Common/Demo/styles.css'
12
+
13
+ const itemArr: number[] = [1, 2, 3, 4]
14
+
15
+ function renderCard({
16
+ index,
17
+ }: {
18
+ index: number
19
+ }) {
20
+ return (
21
+ <SwiperItem>
22
+ <Card
23
+ index={index}
24
+ style={{
25
+ height: '200px',
26
+ }}
27
+ />
28
+ </SwiperItem>
29
+ )
30
+ }
12
31
 
13
32
  function SwiperEntry() {
14
33
  return (
15
- <scroll-view scroll-y style='height: 230px'>
16
- <view>
17
- <text>Test Swiper in scroll-view</text>
34
+ <scroll-view
35
+ className='demo-scroll-container lunaris-dark'
36
+ scroll-orientation='vertical'
37
+ >
38
+ <view className='top-area' />
39
+ <view className='demo-section'>
40
+ <text className='demo-section-title'>Horizontal Swipe Only</text>
41
+ <text className='demo-section-description'>
42
+ Swiper stays horizontal while the parent scroll-view moves vertically.
43
+ </text>
18
44
  </view>
19
- <Swiper
20
- data={colorsArr}
21
- itemWidth={250}
22
- itemHeight={200}
23
- loop={false}
24
- duration={500}
25
- initialIndex={0}
26
- mode='normal'
27
- modeConfig={{
28
- align: 'start',
29
- }}
30
- bounceConfig={{
31
- enable: true,
32
- startBounceItemWidth: 0,
33
- endBounceItem: (
34
- <view style='display: linear; linear-orientation: vertical; height: 100%; width: 30px;'>
35
- <text>12345</text>
36
- </view>
37
- ),
38
- onEndBounceItemBounce: ({ type }) => {
39
- console.log('onBounce result', type)
40
- },
41
- }}
42
- experimentalHorizontalSwipeOnly={true}
43
- >
44
- {({ item, index, realIndex }) => (
45
- <SwiperItem index={index} key={realIndex} realIndex={realIndex}>
46
- <view
47
- class='block-view'
48
- style={{
49
- width: '100%',
50
- height: '100%',
51
- backgroundColor: item,
52
- display: 'flex',
53
- justifyContent: 'center',
54
- alignItems: 'center',
55
- }}
56
- >
57
- <view
58
- style={{
59
- backgroundColor: 'white',
60
- width: '4px',
61
- height: '4px',
62
- }}
63
- >
45
+ <view className='content-area content-area--compact'>
46
+ <Swiper
47
+ data={itemArr}
48
+ itemWidth={250}
49
+ itemHeight={200}
50
+ containerWidth={lynx.__globalProps.screenWidth - 32
51
+ || SystemInfo.pixelWidth / SystemInfo.pixelRatio - 32}
52
+ loop={false}
53
+ duration={500}
54
+ initialIndex={0}
55
+ mode='normal'
56
+ modeConfig={{
57
+ align: 'start',
58
+ spaceBetween: 16,
59
+ }}
60
+ bounceConfig={{
61
+ enable: true,
62
+ startBounceItemWidth: 0,
63
+ endBounceItem: (
64
+ <view className='bounce-item'>
65
+ <text className='bounce-item-text'>End</text>
64
66
  </view>
65
- </view>
66
- <text class='image-text'>Number.{index}</text>
67
- </SwiperItem>
68
- )}
69
- </Swiper>
70
- <Swiper
71
- data={colorsArr}
72
- itemWidth={250}
73
- itemHeight={200}
74
- loop={false}
75
- duration={500}
76
- initialIndex={0}
77
- mode='normal'
78
- modeConfig={{
79
- align: 'start',
80
- }}
81
- bounceConfig={{
82
- enable: true,
83
- startBounceItemWidth: 0,
84
- endBounceItem: (
85
- <view style='display: linear; linear-orientation: vertical; height: 100%; width: 30px;'>
86
- <text>12345</text>
87
- </view>
88
- ),
89
- onEndBounceItemBounce: ({ type }) => {
90
- console.log('onBounce result', type)
91
- },
92
- }}
93
- experimentalHorizontalSwipeOnly={true}
94
- >
95
- {({ item, index, realIndex }) => (
96
- <SwiperItem index={index} key={realIndex} realIndex={realIndex}>
97
- <view
98
- class='block-view'
99
- style={{
100
- width: '100%',
101
- height: '100%',
102
- backgroundColor: item,
103
- display: 'flex',
104
- justifyContent: 'center',
105
- alignItems: 'center',
106
- }}
107
- >
108
- <view
109
- style={{
110
- backgroundColor: 'white',
111
- width: '4px',
112
- height: '4px',
113
- }}
114
- >
67
+ ),
68
+ onEndBounceItemBounce: ({ type }) => {
69
+ console.log('onBounce result', type)
70
+ },
71
+ }}
72
+ experimentalHorizontalSwipeOnly={true}
73
+ style={{
74
+ overflow: 'visible',
75
+ }}
76
+ >
77
+ {renderCard}
78
+ </Swiper>
79
+ <Swiper
80
+ data={itemArr}
81
+ itemWidth={250}
82
+ itemHeight={200}
83
+ containerWidth={lynx.__globalProps.screenWidth - 32
84
+ || SystemInfo.pixelWidth / SystemInfo.pixelRatio - 32}
85
+ loop={false}
86
+ duration={500}
87
+ initialIndex={0}
88
+ mode='normal'
89
+ modeConfig={{
90
+ align: 'start',
91
+ spaceBetween: 16,
92
+ }}
93
+ bounceConfig={{
94
+ enable: true,
95
+ startBounceItemWidth: 0,
96
+ endBounceItem: (
97
+ <view className='bounce-item'>
98
+ <text className='bounce-item-text'>End</text>
115
99
  </view>
116
- </view>
117
- <text class='image-text'>Number.{index}</text>
118
- </SwiperItem>
119
- )}
120
- </Swiper>
100
+ ),
101
+ onEndBounceItemBounce: ({ type }) => {
102
+ console.log('onBounce result', type)
103
+ },
104
+ }}
105
+ experimentalHorizontalSwipeOnly={true}
106
+ style={{
107
+ overflow: 'visible',
108
+ }}
109
+ >
110
+ {renderCard}
111
+ </Swiper>
112
+ </view>
121
113
  </scroll-view>
122
114
  )
123
115
  }