@momo-kits/calendar 0.169.4-beta.3 → 0.169.4
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.
- package/ContainerContext.ts +1 -12
- package/MonthList.tsx +9 -11
- package/index.tsx +2 -15
- package/package.json +1 -1
- package/styles.ts +0 -2
package/ContainerContext.ts
CHANGED
|
@@ -1,14 +1,3 @@
|
|
|
1
1
|
import { createContext } from 'react';
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
export const SCALE_PROBE_SIZE = 100;
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* Calendar container size: `width`/`height` are style sizes for layout, `pageWidth` is
|
|
8
|
-
* the rendered width that horizontal paging and scroll offsets are measured in.
|
|
9
|
-
*/
|
|
10
|
-
export const ContainerContext = createContext({
|
|
11
|
-
width: 0,
|
|
12
|
-
height: 0,
|
|
13
|
-
pageWidth: 0,
|
|
14
|
-
});
|
|
3
|
+
export const ContainerContext = createContext({ width: 0, height: 0 });
|
package/MonthList.tsx
CHANGED
|
@@ -111,24 +111,22 @@ const MonthList = forwardRef<MonthListRef, MonthListProps>((props, ref) => {
|
|
|
111
111
|
|
|
112
112
|
// paging keeps the old pixel offset when the width changes (fold, unfold,
|
|
113
113
|
// rotation), so remember the offset and move back onto the same month
|
|
114
|
-
const scrollOffset = useRef(
|
|
115
|
-
|
|
116
|
-
);
|
|
117
|
-
const pageWidth = useRef(size.pageWidth);
|
|
114
|
+
const scrollOffset = useRef(Math.max(currentScrollIndex, 0) * size.width);
|
|
115
|
+
const pageWidth = useRef(size.width);
|
|
118
116
|
|
|
119
117
|
useLayoutEffect(() => {
|
|
120
118
|
const previousWidth = pageWidth.current;
|
|
121
|
-
pageWidth.current = size.
|
|
122
|
-
if (previousWidth === size.
|
|
119
|
+
pageWidth.current = size.width;
|
|
120
|
+
if (previousWidth === size.width || previousWidth <= 0) {
|
|
123
121
|
return;
|
|
124
122
|
}
|
|
125
123
|
const page = Math.round(scrollOffset.current / previousWidth);
|
|
126
|
-
scrollOffset.current = page * size.
|
|
124
|
+
scrollOffset.current = page * size.width;
|
|
127
125
|
listRef.current?.scrollToOffset({
|
|
128
126
|
offset: scrollOffset.current,
|
|
129
127
|
animated: false,
|
|
130
128
|
});
|
|
131
|
-
}, [size.
|
|
129
|
+
}, [size.width]);
|
|
132
130
|
|
|
133
131
|
const onScroll = useCallback(
|
|
134
132
|
(e: NativeSyntheticEvent<NativeScrollEvent>) => {
|
|
@@ -190,11 +188,11 @@ const MonthList = forwardRef<MonthListRef, MonthListProps>((props, ref) => {
|
|
|
190
188
|
|
|
191
189
|
const getItemLayout = useCallback(
|
|
192
190
|
(_: any, index: number) => ({
|
|
193
|
-
length: size.
|
|
194
|
-
offset: size.
|
|
191
|
+
length: size.width,
|
|
192
|
+
offset: size.width * index,
|
|
195
193
|
index,
|
|
196
194
|
}),
|
|
197
|
-
[size.
|
|
195
|
+
[size.width],
|
|
198
196
|
);
|
|
199
197
|
|
|
200
198
|
const renderItem = useCallback(
|
package/index.tsx
CHANGED
|
@@ -11,7 +11,7 @@ import {
|
|
|
11
11
|
import CalendarPro from './CalendarPro';
|
|
12
12
|
import { HeaderPanel, SwitchReturnSelection } from './CalendarHeader';
|
|
13
13
|
import { CalendarProps, CalendarProRef, TabHeaderRef } from './types';
|
|
14
|
-
import { ContainerContext
|
|
14
|
+
import { ContainerContext } from './ContainerContext';
|
|
15
15
|
import styles from './styles';
|
|
16
16
|
|
|
17
17
|
const DOUBLE = 'doubleDate';
|
|
@@ -51,8 +51,6 @@ const Calendar: React.FC<CalendarProps> = props => {
|
|
|
51
51
|
const [containerWidth, setContainerWidth] = useState<number>(
|
|
52
52
|
Dimensions.get('window').width,
|
|
53
53
|
);
|
|
54
|
-
// rendered size per style unit, read from a probe of known style width
|
|
55
|
-
const [layoutScale, setLayoutScale] = useState(1);
|
|
56
54
|
const [isDoubleDateMode, setIsDoubleDateMode] = useState<boolean>(
|
|
57
55
|
mode === DOUBLE,
|
|
58
56
|
);
|
|
@@ -106,11 +104,6 @@ const Calendar: React.FC<CalendarProps> = props => {
|
|
|
106
104
|
const onLayout = (e: LayoutChangeEvent) =>
|
|
107
105
|
setContainerWidth(e.nativeEvent.layout.width);
|
|
108
106
|
|
|
109
|
-
const handleProbeLayout = (e: LayoutChangeEvent) => {
|
|
110
|
-
const ratio = e.nativeEvent.layout.width / SCALE_PROBE_SIZE;
|
|
111
|
-
if (ratio > 0) setLayoutScale(ratio);
|
|
112
|
-
};
|
|
113
|
-
|
|
114
107
|
const onChangeTab = (tabId: number) => {
|
|
115
108
|
onChangeTabProp?.(tabId);
|
|
116
109
|
tabSelected.current = tabId;
|
|
@@ -259,17 +252,11 @@ const Calendar: React.FC<CalendarProps> = props => {
|
|
|
259
252
|
return (
|
|
260
253
|
<ContainerContext.Provider
|
|
261
254
|
value={{
|
|
262
|
-
width: containerWidth
|
|
255
|
+
width: containerWidth,
|
|
263
256
|
height: priceList ? scaledHeight48 : scaledHeight34,
|
|
264
|
-
pageWidth: containerWidth,
|
|
265
257
|
}}
|
|
266
258
|
>
|
|
267
259
|
<View onLayout={onLayout} style={[style, styles.scrollView]}>
|
|
268
|
-
<View
|
|
269
|
-
pointerEvents="none"
|
|
270
|
-
style={styles.scaleProbe}
|
|
271
|
-
onLayout={handleProbeLayout}
|
|
272
|
-
/>
|
|
273
260
|
<View
|
|
274
261
|
style={[
|
|
275
262
|
{
|
package/package.json
CHANGED
package/styles.ts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import {StyleSheet} from 'react-native';
|
|
2
2
|
import {Colors, Radius, Spacing} from '@momo-kits/foundation';
|
|
3
|
-
import {SCALE_PROBE_SIZE} from './ContainerContext';
|
|
4
3
|
|
|
5
4
|
export default StyleSheet.create({
|
|
6
5
|
//calendar
|
|
@@ -101,7 +100,6 @@ export default StyleSheet.create({
|
|
|
101
100
|
borderTopRightRadius: Radius.XS,
|
|
102
101
|
borderBottomRightRadius: Radius.XS,
|
|
103
102
|
},
|
|
104
|
-
scaleProbe: {position: 'absolute', width: SCALE_PROBE_SIZE, height: 0},
|
|
105
103
|
invisible: {
|
|
106
104
|
height: 0,
|
|
107
105
|
width: 0,
|