react-native-hilal 0.1.0 → 0.2.0

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 (57) hide show
  1. package/README.md +119 -40
  2. package/lib/module/calendar/Appear.js +75 -0
  3. package/lib/module/calendar/Appear.js.map +1 -0
  4. package/lib/module/calendar/DayCell.js +4 -1
  5. package/lib/module/calendar/DayCell.js.map +1 -1
  6. package/lib/module/calendar/HilalCalendar.js +341 -64
  7. package/lib/module/calendar/HilalCalendar.js.map +1 -1
  8. package/lib/module/calendar/PickerGrid.js +66 -0
  9. package/lib/module/calendar/PickerGrid.js.map +1 -0
  10. package/lib/module/calendar/month.js +135 -22
  11. package/lib/module/calendar/month.js.map +1 -1
  12. package/lib/module/calendar/styles.js +219 -6
  13. package/lib/module/calendar/styles.js.map +1 -1
  14. package/lib/module/calendar/theme.js +3 -3
  15. package/lib/module/calendar/theme.js.map +1 -1
  16. package/lib/module/core/convert.js +52 -21
  17. package/lib/module/core/convert.js.map +1 -1
  18. package/lib/module/core/index.js.map +1 -1
  19. package/lib/module/core/locale.js +5 -2
  20. package/lib/module/core/locale.js.map +1 -1
  21. package/lib/typescript/src/calendar/Appear.d.ts +22 -0
  22. package/lib/typescript/src/calendar/Appear.d.ts.map +1 -0
  23. package/lib/typescript/src/calendar/DayCell.d.ts +3 -1
  24. package/lib/typescript/src/calendar/DayCell.d.ts.map +1 -1
  25. package/lib/typescript/src/calendar/HilalCalendar.d.ts +1 -1
  26. package/lib/typescript/src/calendar/HilalCalendar.d.ts.map +1 -1
  27. package/lib/typescript/src/calendar/PickerGrid.d.ts +28 -0
  28. package/lib/typescript/src/calendar/PickerGrid.d.ts.map +1 -0
  29. package/lib/typescript/src/calendar/index.d.ts +1 -1
  30. package/lib/typescript/src/calendar/index.d.ts.map +1 -1
  31. package/lib/typescript/src/calendar/month.d.ts +30 -7
  32. package/lib/typescript/src/calendar/month.d.ts.map +1 -1
  33. package/lib/typescript/src/calendar/styles.d.ts +200 -113
  34. package/lib/typescript/src/calendar/styles.d.ts.map +1 -1
  35. package/lib/typescript/src/calendar/theme.d.ts +21 -1
  36. package/lib/typescript/src/calendar/theme.d.ts.map +1 -1
  37. package/lib/typescript/src/calendar/types.d.ts +106 -2
  38. package/lib/typescript/src/calendar/types.d.ts.map +1 -1
  39. package/lib/typescript/src/core/convert.d.ts +38 -15
  40. package/lib/typescript/src/core/convert.d.ts.map +1 -1
  41. package/lib/typescript/src/core/index.d.ts +1 -1
  42. package/lib/typescript/src/core/index.d.ts.map +1 -1
  43. package/lib/typescript/src/core/locale.d.ts +1 -1
  44. package/lib/typescript/src/core/locale.d.ts.map +1 -1
  45. package/package.json +1 -1
  46. package/src/calendar/Appear.tsx +94 -0
  47. package/src/calendar/DayCell.tsx +6 -0
  48. package/src/calendar/HilalCalendar.tsx +406 -77
  49. package/src/calendar/PickerGrid.tsx +99 -0
  50. package/src/calendar/index.ts +6 -1
  51. package/src/calendar/month.ts +174 -23
  52. package/src/calendar/styles.ts +235 -5
  53. package/src/calendar/theme.ts +23 -3
  54. package/src/calendar/types.ts +109 -2
  55. package/src/core/convert.ts +87 -23
  56. package/src/core/index.ts +1 -0
  57. package/src/core/locale.ts +4 -1
@@ -0,0 +1,94 @@
1
+ import { useEffect, useState, type ReactNode } from 'react';
2
+ import {
3
+ AccessibilityInfo,
4
+ Animated,
5
+ Easing,
6
+ Platform,
7
+ View,
8
+ type LayoutChangeEvent,
9
+ type StyleProp,
10
+ type ViewStyle,
11
+ } from 'react-native';
12
+
13
+ const DURATION = 220;
14
+ /** Scale the content starts from, just under its full size. */
15
+ const FROM_SCALE = 0.96;
16
+
17
+ type AppearProps = {
18
+ /**
19
+ * Fade and zoom in on mount. False renders a plain View. Read once, on
20
+ * mount, so the content never remounts when it changes.
21
+ */
22
+ animate: boolean;
23
+ style?: StyleProp<ViewStyle>;
24
+ onLayout?: (event: LayoutChangeEvent) => void;
25
+ children: ReactNode;
26
+ };
27
+
28
+ /**
29
+ * Fades its content in with a slight zoom when it mounts, so switching
30
+ * between the days and the month or year picker is not an abrupt jump.
31
+ * Give it a new `key` to play it again.
32
+ */
33
+ export function Appear({ animate, style, onLayout, children }: AppearProps) {
34
+ const [animated] = useState(animate);
35
+ const [progress] = useState(() => new Animated.Value(animated ? 0 : 1));
36
+
37
+ useEffect(() => {
38
+ if (!animated) {
39
+ return;
40
+ }
41
+ const animation = Animated.timing(progress, {
42
+ toValue: 1,
43
+ duration: DURATION,
44
+ easing: Easing.out(Easing.cubic),
45
+ // React Native Web has no native animation driver.
46
+ useNativeDriver: Platform.OS !== 'web',
47
+ });
48
+ animation.start();
49
+ return () => animation.stop();
50
+ // Plays once, on mount.
51
+ // eslint-disable-next-line react-hooks/exhaustive-deps
52
+ }, []);
53
+
54
+ if (!animated) {
55
+ return (
56
+ <View style={style} onLayout={onLayout}>
57
+ {children}
58
+ </View>
59
+ );
60
+ }
61
+ const scale = progress.interpolate({
62
+ inputRange: [0, 1],
63
+ outputRange: [FROM_SCALE, 1],
64
+ });
65
+ return (
66
+ <Animated.View
67
+ style={[style, { opacity: progress, transform: [{ scale }] }]}
68
+ onLayout={onLayout}
69
+ >
70
+ {children}
71
+ </Animated.View>
72
+ );
73
+ }
74
+
75
+ /** Whether the user asked the system to reduce motion. */
76
+ export function useReduceMotion() {
77
+ const [reduceMotion, setReduceMotion] = useState(false);
78
+ useEffect(() => {
79
+ let mounted = true;
80
+ AccessibilityInfo.isReduceMotionEnabled().then(
81
+ (enabled) => mounted && setReduceMotion(enabled),
82
+ () => {}
83
+ );
84
+ const subscription = AccessibilityInfo.addEventListener(
85
+ 'reduceMotionChanged',
86
+ setReduceMotion
87
+ );
88
+ return () => {
89
+ mounted = false;
90
+ subscription.remove();
91
+ };
92
+ }, []);
93
+ return reduceMotion;
94
+ }
@@ -19,6 +19,8 @@ export type DayCellProps = {
19
19
  disabled: boolean;
20
20
  styles: CalendarStyles;
21
21
  dayStyle: StyleProp<ViewStyle>;
22
+ /** maxFontSizeMultiplier of the texts. */
23
+ maxFontScale: number;
22
24
  onSelect: (epochDay: number) => void;
23
25
  };
24
26
 
@@ -37,6 +39,7 @@ export function DayCellView({
37
39
  disabled,
38
40
  styles,
39
41
  dayStyle,
42
+ maxFontScale,
40
43
  onSelect,
41
44
  }: DayCellProps) {
42
45
  return (
@@ -56,9 +59,11 @@ export function DayCellView({
56
59
  ]}
57
60
  >
58
61
  <Text
62
+ maxFontSizeMultiplier={maxFontScale}
59
63
  style={[
60
64
  styles.dayText,
61
65
  disabled && styles.disabledText,
66
+ today && styles.todayText,
62
67
  selected && styles.selectedText,
63
68
  ]}
64
69
  >
@@ -66,6 +71,7 @@ export function DayCellView({
66
71
  </Text>
67
72
  {secondaryLabel !== null && (
68
73
  <Text
74
+ maxFontSizeMultiplier={maxFontScale}
69
75
  style={[
70
76
  styles.secondaryText,
71
77
  disabled && styles.disabledText,