打开屏幕只在第一次有效?
Opening a screen only works right the first time?
我想显示用户正在关注谁/他们的关注者。这适用于我单击的第一个配置文件,但不适用于后续配置文件。
- 单击用户个人资料 [deven]:
- 点击 deven 的 关注者:
- 关注者正确显示。 从此屏幕点击用户:
- 单击 elontuskstusk 的 关注者会将我带回 deven 的关注者页面,而不是显示 elontuskstusk 的关注者列表。
我如何打开 follower/following 页面:
openFollowingList = () => {
this.props.navigation.navigate('ClickedFollowPage', {
clickedUID: this.state.userUID,
followers_following: 'following',
navigation: this.props.navigation
})
}
openFollowerList = () => {
this.props.navigation.navigate('ClickedFollowPage', {
clickedUID: this.state.userUID,
followers_following: 'followers',
navigation: this.props.navigation
})
}
follower/following 页面的代码:
class ClickedFollowPage extends React.Component {
constructor(props) {
super(props)
this.state = {
clickedUID: this.props.route.params.clickedUID,
followers_following: this.props.route.params.followers_following,
//Other Stuff
isLoading: true,
navigation: this.props.navigation,
userFollowerFollowingArray: [],
}
this.firestoreRef =
Firebase.firestore()
.collection(this.state.followers_following)
.doc(this.state.clickedUID)
.collection(this.state.followers_following)
}
//Do this every time the component mounts
//----------------------------------------------------------
componentDidMount() {
this.setState({ isLoading: true });
this.unsubscribe = this.firestoreRef.onSnapshot(this.getCollection)
}
componentWillUnmount() {
this.unsubscribe()
}
_refresh = () => {
this.setState({ isLoading: true });
this.firestoreRef.onSnapshot(this.getCollection)
};
getCollection = (querySnapshot) => {
const userFollowerFollowingArray = [];
querySnapshot.forEach((res) => {
userFollowerFollowingArray.push(res.id)
})
this.setState({userFollowerFollowingArray, isLoading: false})
}
我传递 1) 单击了哪个用户,以及 2) 是否单击了以下或关注者列表。
根据这些信息,我向 firestore 查询了正确的列表。这有效,但只是第一次。
然后,如果我单击此列表中的用户并单击他们的关注者列表,我将返回到上一个用户的关注者列表。
我该如何解决这个问题?
超级简单的解决方案。将 this.props.navigation.navigate 更改为 this.props.navigation.push
openFollowingList = () => {
this.props.navigation.navigate('ClickedFollowPage', {
clickedUID: this.state.userUID,
followers_following: 'following',
navigation: this.props.navigation
})
}
openFollowerList = () => {
this.props.navigation.navigate('ClickedFollowPage', {
clickedUID: this.state.userUID,
followers_following: 'followers',
navigation: this.props.navigation
})
}
我想显示用户正在关注谁/他们的关注者。这适用于我单击的第一个配置文件,但不适用于后续配置文件。
- 单击用户个人资料 [deven]:
- 点击 deven 的 关注者:
- 关注者正确显示。 从此屏幕点击用户:
- 单击 elontuskstusk 的 关注者会将我带回 deven 的关注者页面,而不是显示 elontuskstusk 的关注者列表。
我如何打开 follower/following 页面:
openFollowingList = () => {
this.props.navigation.navigate('ClickedFollowPage', {
clickedUID: this.state.userUID,
followers_following: 'following',
navigation: this.props.navigation
})
}
openFollowerList = () => {
this.props.navigation.navigate('ClickedFollowPage', {
clickedUID: this.state.userUID,
followers_following: 'followers',
navigation: this.props.navigation
})
}
follower/following 页面的代码:
class ClickedFollowPage extends React.Component {
constructor(props) {
super(props)
this.state = {
clickedUID: this.props.route.params.clickedUID,
followers_following: this.props.route.params.followers_following,
//Other Stuff
isLoading: true,
navigation: this.props.navigation,
userFollowerFollowingArray: [],
}
this.firestoreRef =
Firebase.firestore()
.collection(this.state.followers_following)
.doc(this.state.clickedUID)
.collection(this.state.followers_following)
}
//Do this every time the component mounts
//----------------------------------------------------------
componentDidMount() {
this.setState({ isLoading: true });
this.unsubscribe = this.firestoreRef.onSnapshot(this.getCollection)
}
componentWillUnmount() {
this.unsubscribe()
}
_refresh = () => {
this.setState({ isLoading: true });
this.firestoreRef.onSnapshot(this.getCollection)
};
getCollection = (querySnapshot) => {
const userFollowerFollowingArray = [];
querySnapshot.forEach((res) => {
userFollowerFollowingArray.push(res.id)
})
this.setState({userFollowerFollowingArray, isLoading: false})
}
我传递 1) 单击了哪个用户,以及 2) 是否单击了以下或关注者列表。
根据这些信息,我向 firestore 查询了正确的列表。这有效,但只是第一次。
然后,如果我单击此列表中的用户并单击他们的关注者列表,我将返回到上一个用户的关注者列表。
我该如何解决这个问题?
超级简单的解决方案。将 this.props.navigation.navigate 更改为 this.props.navigation.push
openFollowingList = () => {
this.props.navigation.navigate('ClickedFollowPage', {
clickedUID: this.state.userUID,
followers_following: 'following',
navigation: this.props.navigation
})
}
openFollowerList = () => {
this.props.navigation.navigate('ClickedFollowPage', {
clickedUID: this.state.userUID,
followers_following: 'followers',
navigation: this.props.navigation
})
}