react-native-calendar-strip icon indicating copy to clipboard operation
react-native-calendar-strip copied to clipboard

Scrollable w/ RTL not rendering properly in Android

Open anastely opened this issue 4 years ago • 20 comments

Hey, I have an issue to render Day names/number in android, It works very well on iOS!

iOS screenshot

Screen Shot 2020-07-30 at 1 24 16 AM

Android screenshot

Screen Shot 2020-07-30 at 1 24 28 AM

dependencies

"moment": "^2.27.0", "react": "16.13.1", "react-native": "0.63.0", "react-native-calendar-strip": "^2.0.8",

what I tried:

  • delete node_modules
  • reset cache
  • set local as default 'en'
  • change styles
  • delete the app then reinstall it.

Nothing works! here's my code snippet

CalendarStrip.js

import React from 'react';
import {View, Text, TouchableOpacity, StyleSheet} from 'react-native';
import CalendarStrip from 'react-native-calendar-strip';
import {locale} from '../utils/local';
import Feather from 'react-native-vector-icons/Feather';

const StripeCalender = (props) => {
  const [dateName, setDateName] = React.useState('');

  const onDateSelected = (date) => {
    setDateName(date.format('D MMMM YYYY'));
  };

  const closeModal = () => {
    props.closeModal();
  };
  return (
    <View style={styles.container}>
      <CalendarStrip
        scrollable={true}
        useNativeDriver
        onDateSelected={onDateSelected}
        style={{height: 250, paddingTop: 50, paddingBottom: 10}}
        calendarColor={'#000'}
        calendarHeaderStyle={{
          color: '#fff',
          fontSize: 22,
        }}
        dateNumberStyle={{fontSize: 17, color: '#fff'}}
        dateNameStyle={{fontSize: 13, color: '#fff'}}
        iconContainer={{flex: 0.1}}
        innerStyle={{
          flexGrow: 1,
          marginTop: 20,
          backgroundColor: '#000',
        }}
        selectedDate={new Date()}
        calendarAnimation={{type: 'sequence', duration: 30}}
        daySelectionAnimation={{
          type: 'background',
          duration: 300,
          highlightColor: '#fff',
        }}
        rightSelector={<Feather name="chevron-left" size={35} color={'#fff'} />}
        leftSelector={<Feather name="chevron-right" size={35} color={'#fff'} />}
        locale={locale}
      />
      <Text style={{fontSize: 24}}>Selected Date: {dateName}</Text>

    </View>
  );
};

export default StripeCalender;

const styles = StyleSheet.create({
  container: {
    flex: 1,
    backgroundColor: '#eee',
  },
});

index.js

...

import 'moment';
import 'moment/locale/ar';

locale.js

export const locale = {
  name: 'ar',
  config: {
    months: [
      'يناير',
      'فبراير',
      'مارس',
      'أبريل',
      'مايو',
      'يونيو',
      'يوليو',
      'أغسطس',
      'سبتمبر',
      'أكتوبر',
      'نوفمبر',
      'ديسمبر',
    ],
    weekdays: 'الأحد_الإثنين_الثلاثاء_الأربعاء_الخميس_الجمعة_السبت'.split(''),
    weekdaysShort: 'الأحد_الإثنين_الثلاثاء_الأربعاء_الخميس_الجمعة_السبت'.split(
      '_',
    ),
    longDateFormat: {
      LT: 'HH:mm',
      LTS: 'HH:mm:ss',
      L: 'D/\u200FM/\u200FYYYY',
      LL: 'D MMMM YYYY',
      LLL: 'D MMMM YYYY HH:mm',
      LLLL: 'dddd D MMMM YYYY HH:mm',
    },
  },
};

anastely avatar Jul 29 '20 22:07 anastely

I tested your code in the example app in this repo. It renders as expected on the Android simulator. It doesn't sound like a locale issue if it's not rendering with the default en locale for you.

Inspect the elements to verify that they're being rendered. Determine whether they're rendered but invisible, or not rendered at all. https://reactnative.dev/docs/debugging#integration-with-react-native-inspector

peacechen avatar Jul 30 '20 05:07 peacechen

Hmm, I'm tested in a physical device, And I don't use Expo if u wondering

Yes, i can see it, check here Screen Shot 2020-07-30 at 3 16 26 PM

Edit

I just faced some strange things! When I come back to November 2019 especially I can see the Items "day/number" other way nothing I can see! I don't know if its bug or something Check this video record to understand what I mean! Here

anastely avatar Jul 30 '20 12:07 anastely

I've tested CalendarStrip on physical Android devices with and without Expo. There must be a difference in your environment or device setting. Are you using RTL layout? If so, try disabling that temporarily.

peacechen avatar Jul 30 '20 16:07 peacechen

Yes you're right, After I disable RTL layout for android in MainApplication.java file it works very well But in my case, my App is fully RTL, How can I solve this issue without disabled RTL?

anastely avatar Jul 30 '20 16:07 anastely

Try passing in the React Native RTL style to the CalendarStrip container. Experiment with the various container(s). You may need to set it on all the nested ones til it gets to the day component.

peacechen avatar Jul 30 '20 21:07 peacechen

@peacechen TBH I don't understand you well? Do you mean to add some RTL style to CalendarStrip styles like "flexDirection: row / row-reverse' Or something else?

anastely avatar Aug 03 '20 17:08 anastely

Bugs have been filed for React Native's ScrollView set to horizontal RTL on Android. https://github.com/facebook/react-native/issues/11960

One of the proposed fixes is to add the style { flexDirection: I18nManager.isRTL ? 'row-reverse' : 'row '} for Android only. RNCS doesn't have a prop that passes through to the inner ScrollView. I will add that, but need your help testing whether row-reverse works.

Edit this line under node_modules/react-native-calendar-strip/src/Scroller.js: https://github.com/BugiDev/react-native-calendar-strip/blob/master/src/Scroller.js#L251

... and add row-reverse to the styles passed to scrollViewProps.

peacechen avatar Aug 03 '20 20:08 peacechen

@peacechen Sadly not works, here's what I add " I just add a background to check if the styles applying or not and yeah I can see the background color but flexDirection not works"

...
 scrollViewProps={{
....
            style: { backgroundColor: '#12a19e', flexDirection: I18nManager.isRTL ? 'row-reverse' : 'row'},
           // contentContainerStyle: {flexDirection: I18nManager.isRTL ? 'row-reverse' : 'row', backgroundColor:"#12a19e", paddingRight: this.state.itemWidth /2}, // and add it here but same not work

....
}}
...

I implement a simple app "with RTL" if you want to test it, here's a repo

anastely avatar Aug 04 '20 20:08 anastely

Thanks for creating a repo that recreates this behavior. Based on the behavior of the days appearing and disappearing, it could be an issue with RecyclerListView. There is an existing issue for this: https://github.com/Flipkart/recyclerlistview/issues/502

peacechen avatar Aug 05 '20 03:08 peacechen

@peacechen Yes I can see, But this issue opened from 3 months ago and not responded 😅 so what should I do in this case, this lib RNCS it's absolutely achieved what I need in my app? No other ways to solve this issue temporarily so I can release my app?

anastely avatar Aug 07 '20 18:08 anastely

You would need to debug RecyclerListView and fix the issue if that's the root cause. I'm concerned that it might not be RLV since it's working properly in iOS.

The only other option at this point is to disable scrollable for Android.

peacechen avatar Aug 07 '20 18:08 peacechen

Yeah, After disable scrollable it's rendering properly I guess the issue with RecyclerListView itself

anastely avatar Aug 10 '20 15:08 anastely

I am also facing same issue when i stop to call onVisibleIndicesChanged method than it's properly but when i scroll the list data goes hide form the list. it is issue of RecyclerListView in RTL in android only

EktaSahuGammastck avatar Nov 20 '20 09:11 EktaSahuGammastck

Is there a some solution for this?

PrgrmmrOleg avatar Mar 03 '21 11:03 PrgrmmrOleg

We may need a new pass-thru prop to send to RecyclerListView's scrollViewProps in Scroller.js. That would allow you to implement work-arounds for RTL ScrollView. https://stackoverflow.com/questions/41036427/scrollview-rtl-in-react-native

Please submit a PR to add this prop

peacechen avatar Mar 03 '21 16:03 peacechen

Any update on this issue? Still facing RTL issue in android @peacechen

ahmadfreijeh avatar Sep 18 '22 05:09 ahmadfreijeh

this issue is opened since 2020 with fixes

omarZaoujal99 avatar Jan 07 '24 00:01 omarZaoujal99

Any Updates? I am still unable to load dates.

ehtshamaziz avatar Apr 03 '24 19:04 ehtshamaziz

Has anyone discovered the solution?

DevSherKhan avatar Apr 18 '24 10:04 DevSherKhan

Has anyone discovered the solution?

Nope, made a custom strip calendar using FlatList for this.

ehtshamaziz avatar Apr 18 '24 13:04 ehtshamaziz