【发布时间】:2021-03-03 14:14:16
【问题描述】:
我需要将此滚动视图转换为平面列表,但由于我没有自己编写代码,所以完全卡住了。
matchesRound 是一个列表,但是当我们映射它时我似乎无法弄清楚配置文件包含,我认为我可以从matchesRound 中创建一个常量并将其用作平面列表中的数据?
<ScrollView
{!user.settings.hidden &&
matchesRound
.sort((a, b) => {
const aLength = a.relation.questions.length;
const bLength = b.relation.questions.length;
if (aLength === 0 && bLength > 0) return -1;
if (aLength > 0 && bLength === 0) return 1;
if (aLength === 0 && bLength === 0)
return b.relation.updatedAt - a.relation.updatedAt;
const aLastQuestion = a.relation.questions[aLength - 1];
const bLastQuestion = b.relation.questions[bLength - 1];
const aHasAnswered =
!!aLastQuestion[user.id] && !aLastQuestion[getOtherUserId(a.relation, user.id)];
const bHasAnswered =
!!bLastQuestion[user.id] && !bLastQuestion[getOtherUserId(b.relation, user.id)];
if (!aHasAnswered && bHasAnswered) return -1;
if (aHasAnswered && !bHasAnswered) return 1;
return aLastQuestion.time - bLastQuestion.time;
})
.map((profile, i) => {
return (
<>
{i == 0 && <View style={{ width: 6 }} />}
<GameCard
key={i + "profile"}
superDM={!!getUserStatus(profile.relation, user.id).superDM}
prime={getUserStatus(profile.relation, user.id).thanksToPrime}
profile={profile}
onPress={() => navigation.navigate("Rounds", { profile: profile })}
/>
</>
);
})}
{(matchesRound.length === 0 || user.settings.hidden) &&
[0, 1, 2].map(key => (
<>
{key == 0 && <View style={{ width: 6 }} />}
<GameCardEmpty key={key + "gameCards"} />
</>
))}
</ScrollView>
【问题讨论】:
标签: react-native scrollview react-native-flatlist