最近,我开始使用以下回购中的日历控件:https://github.com/wix/react-native-calendars 最初,日历控件会正确对齐所有项目,但是似乎有些东西完全破坏了对齐。
在此图像上方,您可以看到从升序到降序的顺序。 使用元素检查器进行更深入的研究:
我已经做了一个消除过程(我认为这可能是由于最近从React-Navigation 2x升级到3x,因为必须明确创建覆盖容器)
我创建了我能做的最简单的问题,然后回滚到React-Navigation 2x。不幸的是,这无法解决问题。
一些来源附在下面:
App.js:
import React from 'react';
import AppNavigator from './navigation/AppNavigator';
export default class App extends React.Component {
render() {
return (
<AppNavigator />
);
}
}
AppNavigator:
//#region imports
import {
createSwitchNavigator,
createStackNavigator
} from 'react-navigation';
import {
HomeScreen,
SettingsScreen,
AuthLoadingScreen,
SignInScreen
} from '../screens';
//#endregion
const appStack = createStackNavigator({
Home: HomeScreen,
Other: SettingsScreen
});
const authStack = createStackNavigator({
SignIn: SignInScreen
});
export default createSwitchNavigator({
AuthLoading: AuthLoadingScreen,
App: appStack,
Auth: authStack
}, { initialRouteName: 'AuthLoading'});
主屏幕:
import React, {Component} from 'react';
import {StyleSheet, View, Text, AsyncStorage, Button} from 'react-native';
import Agenda from '../components/Agenda';
export default class HomeScreen extends Component{
logout = async () => {
const userToken = await AsyncStorage.removeItem('userToken');
// This will switch to the App screen or Auth screen and this loading
// screen will be unmounted and thrown away.
this.props.navigation.navigate('Auth');
}
render(){
return <Agenda/>;
}
}
议程:
import React, { Component } from 'react';
import {
Text,
View,
StyleSheet
} from 'react-native';
import {Agenda} from 'react-native-calendars';
export default class AgendaScreen extends Component {
constructor(props) {
super(props);
this.state = {
items: {}
};
}
render() {
return (
<Agenda
items={this.state.items}
loadItemsForMonth={this.loadItems.bind(this)}
selected={'2017-05-16'}
renderItem={this.renderItem.bind(this)}
renderEmptyDate={this.renderEmptyDate.bind(this)}
rowHasChanged={this.rowHasChanged.bind(this)}
// markingType={'period'}
// markedDates={{
// '2017-05-08': {textColor: '#666'},
// '2017-05-09': {textColor: '#666'},
// '2017-05-14': {startingDay: true, endingDay: true, color: 'blue'},
// '2017-05-21': {startingDay: true, color: 'blue'},
// '2017-05-22': {endingDay: true, color: 'gray'},
// '2017-05-24': {startingDay: true, color: 'gray'},
// '2017-05-25': {color: 'gray'},
// '2017-05-26': {endingDay: true, color: 'gray'}}}
// monthFormat={'yyyy'}
// theme={{calendarBackground: 'red', agendaKnobColor: 'green'}}
//renderDay={(day, item) => (<Text>{day ? day.day: 'item'}</Text>)}
/>
);
}
loadItems(day) {
setTimeout(() => {
for (let i = -15; i < 85; i++) {
const time = day.timestamp + i * 24 * 60 * 60 * 1000;
const strTime = this.timeToString(time);
if (!this.state.items[strTime]) {
this.state.items[strTime] = [];
const numItems = Math.floor(Math.random() * 5);
for (let j = 0; j < numItems; j++) {
this.state.items[strTime].push({
name: 'Item for ' + strTime,
height: Math.max(50, Math.floor(Math.random() * 150))
});
}
}
}
//console.log(this.state.items);
const newItems = {};
Object.keys(this.state.items).forEach(key => {newItems[key] = this.state.items[key];});
this.setState({
items: newItems
});
}, 1000);
// console.log(`Load Items for ${day.year}-${day.month}`);
}
renderItem(item) {
return (
<View style={[styles.item, {height: item.height}]}><Text>{item.name}</Text></View>
);
}
renderEmptyDate() {
return (
<View style={styles.emptyDate}><Text>This is empty date!</Text></View>
);
}
rowHasChanged(r1, r2) {
return r1.name !== r2.name;
}
timeToString(time) {
const date = new Date(time);
return date.toISOString().split('T')[0];
}
}
const styles = StyleSheet.create({
item: {
backgroundColor: 'white',
flex: 1,
borderRadius: 5,
padding: 10,
marginRight: 10,
marginTop: 17
},
emptyDate: {
height: 15,
flex:1,
paddingTop: 30
}
});
关于代码质量的道歉,所有这些都来自示例。 议程样本来源:https://github.com/wix/react-native-calendars/blob/master/example/src/screens/agenda.js
路由器来源:https://reactnavigation.org/docs/en/2.x/auth-flow.html
任何帮助都值得赞赏。
答案 0 :(得分:1)
虽然回答自己的问题是在社交场合中与在公众场合中高昂的自我嘲讽相提并论,但是如果其他任何人都遇到了这个问题,请不要为烦恼和压力而烦恼。
我做了很多尝试来诊断问题,从创建空白脚手架看问题是否仍然存在(确实如此)。
我最后决定在同事的电话上进行测试(惊讶的是,它可以正确显示)。
删除expo应用程序,重新安装并从命令expo start --clear
开始,然后恢复正常状态。