Skip to content

Commit b20a0e5

Browse files
committed
added independent rtl support
1 parent ed42258 commit b20a0e5

4 files changed

Lines changed: 18 additions & 15 deletions

File tree

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ const styles = StyleSheet.create({
8080
## PersianCalendarPicker props
8181
| Prop | Type | Description |
8282
:------------ |:---------------| :-----|
83+
| **`rtl`** | `Boolean` | Optional. Force layout to be rtl. Default is `false` |
8384
| **`weekdays`** | `Array` | Optional. List of week days. Eg. `['Sat', 'Sun', ...]` Must be 7 days |
8485
| **`months`** | `Array` | Optional. List of months names. Eg. `['Farvardin', 'Ordibehesht', ...]` Must be 12 months |
8586
| **`allowRangeSelection`** | `Boolean` | Optional. Allow to select date ranges. Default is `false` |

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "react-native-persian-calendar-picker",
3-
"version": "2.0.0",
3+
"version": "2.1.0",
44
"description": "Persian (Jalaali) Calendar Picker Component for React Native",
55
"main": "src/index.js",
66
"scripts": {

src/index.js

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,14 @@ const _swipeConfig = {
2727
};
2828

2929
class PersianCalendarPicker extends React.Component {
30+
static defaultProps = {
31+
rtl: false,
32+
initialDate: jMoment.utc(),
33+
scaleFactor: 375,
34+
enableSwipe: true,
35+
onDateChange: () => console.log('onDateChange() not provided'),
36+
};
37+
3038
constructor(props) {
3139
super(props);
3240
this.state = {
@@ -46,13 +54,6 @@ class PersianCalendarPicker extends React.Component {
4654
this.onSwipe = this.onSwipe.bind(this);
4755
}
4856

49-
static defaultProps = {
50-
initialDate: jMoment.utc(),
51-
scaleFactor: 375,
52-
enableSwipe: true,
53-
onDateChange: () => console.log('onDateChange() not provided'),
54-
};
55-
5657
componentDidUpdate(prevProps, prevState) {
5758
let newStyles = {};
5859
let doStateUpdate = false;
@@ -89,6 +90,7 @@ class PersianCalendarPicker extends React.Component {
8990

9091
updateScaledStyles(props) {
9192
const {
93+
rtl,
9294
scaleFactor,
9395
selectedDayColor,
9496
selectedDayTextColor,
@@ -100,7 +102,7 @@ class PersianCalendarPicker extends React.Component {
100102
const containerWidth = width ? width : Dimensions.get('window').width;
101103
const containerHeight = height ? height : Dimensions.get('window').height;
102104
const initialScale = Math.min(containerWidth, containerHeight) / scaleFactor;
103-
return {styles: makeStyles(initialScale, selectedDayColor, selectedDayTextColor, todayBackgroundColor)};
105+
return {styles: makeStyles({rtl, initialScale, selectedDayColor, selectedDayTextColor, todayBackgroundColor})};
104106
}
105107

106108
updateMonthYear(initialDate = this.props.initialDate) {

src/style.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ const DEFAULT_SELECTED_BACKGROUND_COLOR = '#5ce600';
1313
const DEFAULT_SELECTED_TEXT_COLOR = '#000000';
1414
const DEFAULT_TODAY_BACKGROUD_COLOR = '#CCCCCC';
1515

16-
function makeStyles(scaler, backgroundColor, textColor, todayBackgroundColor) {
16+
function makeStyles({rtl, initialScale: scaler, backgroundColor, textColor, todayBackgroundColor}) {
1717
const SELECTED_BG_COLOR = backgroundColor ? backgroundColor : DEFAULT_SELECTED_BACKGROUND_COLOR;
1818
const SELECTED_TEXT_COLOR = textColor ? textColor : DEFAULT_SELECTED_TEXT_COLOR;
1919
const TODAY_BG_COLOR = todayBackgroundColor ? todayBackgroundColor : DEFAULT_TODAY_BACKGROUD_COLOR;
@@ -43,7 +43,7 @@ function makeStyles(scaler, backgroundColor, textColor, todayBackgroundColor) {
4343
},
4444

4545
dayLabelsWrapper: {
46-
flexDirection: 'row',
46+
flexDirection: rtl ? 'row-reverse' : 'row',
4747
borderBottomWidth: 1,
4848
borderTopWidth: 1,
4949
paddingTop: 10 * scaler,
@@ -133,7 +133,7 @@ function makeStyles(scaler, backgroundColor, textColor, todayBackgroundColor) {
133133

134134
headerWrapper: {
135135
alignItems: 'center',
136-
flexDirection: 'row',
136+
flexDirection: rtl ? 'row-reverse' : 'row',
137137
alignSelf: 'center',
138138
padding: 5 * scaler,
139139
paddingBottom: 3 * scaler,
@@ -147,11 +147,11 @@ function makeStyles(scaler, backgroundColor, textColor, todayBackgroundColor) {
147147
},
148148

149149
prev: {
150-
textAlign: 'left',
150+
textAlign: rtl ? 'right' : 'left',
151151
},
152152

153153
next: {
154-
textAlign: 'right',
154+
textAlign: rtl ? 'left' : 'right',
155155
},
156156

157157
yearLabel: {
@@ -166,7 +166,7 @@ function makeStyles(scaler, backgroundColor, textColor, todayBackgroundColor) {
166166
},
167167

168168
weekRow: {
169-
flexDirection: 'row',
169+
flexDirection: rtl ? 'row-reverse' : 'row',
170170
},
171171

172172
disabledText: {

0 commit comments

Comments
 (0)