Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

day range missing on first open #423

Open
ddikodroid opened this issue Sep 5, 2024 · 2 comments
Open

day range missing on first open #423

ddikodroid opened this issue Sep 5, 2024 · 2 comments
Labels
bug Something isn't working needs more info Needs more information needs repro Needs reproducible example

Comments

@ddikodroid
Copy link
Contributor

Current behaviour

when I open DatePickerModal for the first time, the range isn't fully selected
Simulator Screenshot - iPhone 15 Pro Max - 2024-09-05 at 21 07 15

Expected behaviour

when I choose the same date range, the range is fully selected
Simulator Screenshot - iPhone 15 Pro Max - 2024-09-05 at 21 50 04

How to reproduce?

const DateRangePicker = forwardRef(
  (
    {
      label,
      onDismiss,
      onConfirm,
    }: {
      label: string;
      onDismiss?: () => void;
      onConfirm?: ({ startDate, endDate }: any) => void;
    },
    ref
  ) => {
    const [open, setOpen] = useState(false);
    const [range, setRange] = useState({
      startDate: dayjs().toDate(),
      endDate: dayjs().add(1, 'week').toDate(),
    });

    const _onDismiss = useCallback(() => {
      setOpen(false);
    }, []);

    const _onConfirm = useCallback(
      ({ startDate, endDate }: any) => {
        setRange({ startDate, endDate });
        setOpen(false);
      },
      [setOpen, setRange]
    );

    useImperativeHandle(ref, () => ({
      open: () => {
        setOpen(true);
      },
      close: () => {
        setOpen(false);
      },
    }));

    const currentLanguage = getLanguage();

    return (
      <View>
        <Text style={globalStyles.textInputLabel}>{label}</Text>
        <Pressable onPress={() => setOpen(true)}>
          <View style={styles.container}>
            <TextInput
              onPressIn={() => setOpen(true)}
              editable={false}
              //outlineStyle is working on web, but not detected on mobile
              // @ts-ignore:next-line
              style={[styles.textInput, isWeb ? { outlineStyle: 'none' } : {}]}
              value={getDateRange(range)}
            />
            <Image
              source={require('@/assets/icons/calendar-days.png')}
              style={{ width: 24, height: 24 }}
              resizeMode='contain'
            />
          </View>
        </Pressable>
        <DatePickerModal
          locale={getLanguageCode(currentLanguage)}
          mode='range'
          visible={open}
          startWeekOnMonday
          onDismiss={() => {
            onDismiss?.();
            _onDismiss();
          }}
          onConfirm={({ startDate, endDate }) => {
            if (dayjs(startDate).isAfter(dayjs(endDate))) {
              Alert.alert(
                i18n.t('error-state.title'),
                i18n.t('error-state.range.quantification-period')
              );
              return;
            }
            onConfirm?.({ startDate, endDate });
            _onConfirm({ startDate, endDate });
          }}
          startDate={range.startDate}
          endDate={range.endDate}
          presentationStyle='pageSheet'
          validRange={{ startDate: dateAfter, endDate: dateBefore }}
        />
      </View>
    );
  }
);

Preview

Above

What have you tried so far?

Try to see where the code responsible for day range on DayRange.tsx

Your Environment

software version
ios 17.4
android -
react-native 0.73.6
react-native-paper ^5.12.3
node 20.11.0
yarn 1.22.21
expo sdk ~50.0.20
@ddikodroid ddikodroid added the bug Something isn't working label Sep 5, 2024
@iM-GeeKy iM-GeeKy added needs more info Needs more information needs repro Needs reproducible example labels Sep 8, 2024
Copy link
Contributor

github-actions bot commented Sep 8, 2024

Hey! Thanks for opening the issue. Can you provide more information about the issue? Please fill the issue template when opening the issue without deleting any section. We need all the information we can, to be able to help. Make sure to at least provide - Current behaviour, Expected behaviour, A way to reproduce the issue with minimal code (link to snack.expo.dev) or a repo on GitHub, and the information about your environment (such as the platform of the device, versions of all the packages etc.).

Copy link
Contributor

github-actions bot commented Sep 8, 2024

Hey! Thanks for opening the issue. Can you provide a minimal repro which demonstrates the issue? Posting a snippet of your code in the issue is useful, but it's not usually straightforward to run. A repro will help us debug the issue faster. Please try to keep the repro as small as possible. The easiest way to provide a repro is on snack.expo.dev. If it's not possible to repro it on snack.expo.dev, then you can also provide the repro in a GitHub repository.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working needs more info Needs more information needs repro Needs reproducible example
Projects
None yet
Development

No branches or pull requests

2 participants