native-pytech 1.0.178 → 1.0.179

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.
@@ -1,3 +1,3 @@
1
1
  import type Props from './types';
2
- declare const _default: import("react").MemoExoticComponent<({ itemKey, label, defaultValue, minDate, maxDate, onValueChange, }: Props) => import("react").JSX.Element>;
2
+ declare const _default: import("react").MemoExoticComponent<({ itemKey, label, selection, defaultValue, minDate, maxDate, onValueChange, }: Props) => import("react").JSX.Element>;
3
3
  export default _default;
@@ -1,3 +1,3 @@
1
1
  import type Props from './types';
2
- declare const _default: import("react").MemoExoticComponent<({ itemKey, label, defaultValue, minDate, maxDate, onValueChange, }: Props) => import("react").JSX.Element>;
2
+ declare const _default: import("react").MemoExoticComponent<({ itemKey, label, selection, defaultValue, minDate, maxDate, onValueChange, }: Props) => import("react").JSX.Element>;
3
3
  export default _default;
@@ -2,28 +2,28 @@ import { Section, DatePicker } from '@expo/ui/swift-ui';
2
2
  import { memo, useCallback, useEffect, useRef, useState } from 'react';
3
3
  import { environment } from '@expo/ui/swift-ui/modifiers';
4
4
  import { usePage } from '../../context/page';
5
- export default memo(({ itemKey, label, defaultValue, minDate, maxDate, onValueChange, }) => {
5
+ export default memo(({ itemKey, label, selection, defaultValue, minDate, maxDate, onValueChange, }) => {
6
6
  const { store, registerItem } = usePage();
7
- const [selection, setSelection] = useState(defaultValue);
7
+ const [_selection, setSelection] = useState(selection);
8
8
  // Key
9
9
  const keyRef = useRef(itemKey);
10
10
  useEffect(() => {
11
11
  keyRef.current = registerItem(itemKey);
12
- _onValueChange(selection ?? new Date());
12
+ _onValueChange(_selection ?? defaultValue ?? new Date());
13
13
  }, []);
14
14
  // Hooks
15
- useEffect(() => setSelection(defaultValue), [defaultValue]);
15
+ useEffect(() => setSelection(selection), [selection]);
16
16
  const _onValueChange = useCallback((value) => {
17
17
  setSelection(value);
18
18
  store.values[keyRef.current ?? 0].set({
19
19
  value: value,
20
- hasChanged: value.getTime() !== defaultValue?.getTime(),
20
+ hasChanged: value.getTime() !== selection?.getTime(),
21
21
  isValid: true,
22
22
  });
23
23
  onValueChange?.(value);
24
24
  }, []);
25
25
  return (<Section>
26
- <DatePicker title={label} selection={selection} onDateChange={_onValueChange} modifiers={[environment('locale', 'es_ES')]} range={{
26
+ <DatePicker title={label} selection={_selection ?? defaultValue} onDateChange={_onValueChange} modifiers={[environment('locale', 'es_ES')]} range={{
27
27
  start: minDate,
28
28
  end: maxDate,
29
29
  }}/>
@@ -5,38 +5,38 @@ import { useApp } from '../../../../../libs/providers/App';
5
5
  import Formats from '../../../../../libs/constants/formats';
6
6
  import { usePage } from '../../context/page';
7
7
  import Colors from '../../../../../libs/constants/colors';
8
- export default memo(({ itemKey, label, defaultValue, minDate, maxDate, onValueChange, }) => {
8
+ export default memo(({ itemKey, label, selection, defaultValue, minDate, maxDate, onValueChange, }) => {
9
9
  const { colorScheme } = useApp();
10
10
  const { store, registerItem } = usePage();
11
- const [selection, setSelection] = useState(defaultValue ?? new Date());
11
+ const [_selection, setSelection] = useState(selection ?? defaultValue ?? new Date());
12
12
  const inputRef = useRef(null);
13
13
  // Key
14
14
  const keyRef = useRef(itemKey);
15
15
  useEffect(() => {
16
16
  keyRef.current = registerItem(itemKey);
17
- _onValueChange(Formats.dateToTextFormat(selection, 'yyyy-MM-dd'));
17
+ _onValueChange(Formats.dateToTextFormat(_selection, 'yyyy-MM-dd'));
18
18
  }, []);
19
19
  // Hooks
20
20
  useEffect(() => {
21
- setSelection(defaultValue ?? new Date());
22
- if (defaultValue === undefined)
23
- _onValueChange(Formats.dateToTextFormat(selection, 'yyyy-MM-dd'));
24
- }, [defaultValue]);
21
+ setSelection(selection ?? defaultValue ?? new Date());
22
+ if (selection === undefined)
23
+ _onValueChange(Formats.dateToTextFormat(_selection, 'yyyy-MM-dd'));
24
+ }, [selection]);
25
25
  const _onValueChange = useCallback((value_str) => {
26
26
  const [year, month, day] = value_str.split('-').map(Number);
27
27
  const value = new Date(year, month - 1, day);
28
28
  setSelection(value);
29
29
  store.values[keyRef.current ?? 0].set({
30
30
  value: value,
31
- hasChanged: value.getTime() !== defaultValue?.getTime(),
31
+ hasChanged: value.getTime() !== selection?.getTime(),
32
32
  isValid: true,
33
33
  });
34
34
  onValueChange?.(value);
35
35
  }, []);
36
36
  return (<Table.Option id={label ?? ''} colorScheme={colorScheme} childrenLeft={<Table.Option.Components.Text text={label ?? 'Seleccione una fecha'}/>} childrenRight={(<>
37
37
  <Pressable onPress={() => inputRef.current?.showPicker()} style={[styles.container, { backgroundColor: Colors.especiales.azul }]}>
38
- <Table.Option.Components.Text text={Formats.dateToTextFormat(selection, 'dd/MM/yyyy')} style={{ color: 'white', userSelect: 'none' }}/>
39
- <input ref={inputRef} type="date" value={Formats.dateToTextFormat(selection, 'yyyy-MM-dd')} onChange={(e) => _onValueChange(e.target.value)} style={{
38
+ <Table.Option.Components.Text text={Formats.dateToTextFormat(_selection, 'dd/MM/yyyy')} style={{ color: 'white', userSelect: 'none' }}/>
39
+ <input ref={inputRef} type="date" value={Formats.dateToTextFormat(_selection, 'yyyy-MM-dd')} onChange={(e) => _onValueChange(e.target.value)} style={{
40
40
  all: 'unset',
41
41
  visibility: 'hidden',
42
42
  width: 0,
@@ -8,7 +8,12 @@ type Props = {
8
8
  */
9
9
  label?: string;
10
10
  /**
11
- Default value of the date picker.
11
+ Selection of the date picker.
12
+ */
13
+ selection?: Date;
14
+ /**
15
+ The value that applies when selection is undefined.
16
+ @default Date()
12
17
  */
13
18
  defaultValue?: Date;
14
19
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "native-pytech",
3
- "version": "1.0.178",
3
+ "version": "1.0.179",
4
4
  "description": "Libreria de React Native Pytech",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",