我正在尝试通过AppContainer传递道具。我能够传递其他组件的信息,但是我不知道如何通过createAppContainer发送道具
在App.js中:
render() {
return (
this.state.isLoggedIn ? <DrawerNavigator /> :
<SignedOutNavigator handler={this.saveUserSettings} />
)
}
在SignedOutNavigator中:
import React from "react";
import { View, Text } from "react-native";
import { createStackNavigator, createAppContainer } from "react-navigation";
import LoginScreen from "../screens/LoginScreen";
const SignedOutNavigator = createStackNavigator({
Login: {
// screen: LoginScreen
screen: props => <LoginScreen screenProps={value => {
// I need to access props from here
// like this.props.handler(value)
}} />,
navigationOptions: ({ navigation }) => ({
header: null,
}),
}
});
export default createAppContainer(SignedOutNavigator);
答案 0 :(得分:2)
好的,我得到了Samuel Vaillant的帮助。我不得不做一些修改。
我的App.js:
render() {
return (
this.state.isLoggedIn ? <DrawerNavigator /> : <SignedOutNavigator
screenProps={{
handler: (settings) => { this.saveUserSettings(settings) }
}}
/>
)
}
我的SignedOutNavigator:
import React from "react";
import { View, Text } from "react-native";
import { createStackNavigator, createAppContainer } from "react-navigation";
import LoginScreen from "../screens/LoginScreen";
const SignedOutNavigator = createStackNavigator({
Login: {
// screen: LoginScreen
screen: screenProps => <LoginScreen screenProps={value => {
screenProps.screenProps.handler(value)
}} />,
navigationOptions: ({ navigation }) => ({
header: null,
}),
}
});
export default createAppContainer(SignedOutNavigator);
答案 1 :(得分:1)
您必须将道具置于screenProps
下,才能在public class RequestEattest {
private RequestContext requestContext;
private Eattest eattest;
public RequestContext getRequestContext() {
return requestContext;
}
public void setRequestContext(RequestContext requestContext) {
this.requestContext = requestContext;
}
public Eattest getEattest() {
return eattest;
}
public void setEattest(Eattest eattest) {
this.eattest = eattest;
}
}
package be.cm.apps.application.beanz;
public class RequestContext {
private String b2bReference;
private String externalReference;
private String creationDate;
private String creationTime;
private String requestorNihii;
private String messageDate;
private String messageTime;
private String receptionDate;
private String receptionTime;
private String requestorType;
private String nippinReference;
public String getReceptionDate() {
return receptionDate;
}
public void setReceptionDate(String receptionDate) {
this.receptionDate = receptionDate;
}
public String getReceptionTime() {
return receptionTime;
}
public void setReceptionTime(String receptionTime) {
this.receptionTime = receptionTime;
}
public String getB2bReference() {
return b2bReference;
}
public void setB2bReference(String b2bReference) {
this.b2bReference = b2bReference;
}
public String getExternalReference() {
return externalReference;
}
public void setExternalReference(String externalReference) {
this.externalReference = externalReference;
}
public String getCreationDate() {
return creationDate;
}
public void setCreationDate(String creationDate) {
this.creationDate = creationDate;
}
public String getCreationTime() {
return creationTime;
}
public void setCreationTime(String creationTime) {
this.creationTime = creationTime;
}
public String getRequestorNihii() {
return requestorNihii;
}
public void setRequestorNihii(String requestorNihii) {
this.requestorNihii = requestorNihii;
}
public String getMessageDate() {
return messageDate;
}
public void setMessageDate(String messageDate) {
this.messageDate = messageDate;
}
public String getMessageTime() {
return messageTime;
}
public void setMessageTime(String messageTime) {
this.messageTime = messageTime;
}
public String getRequestorType() {
return requestorType;
}
public void setRequestorType(String requestorType) {
this.requestorType = requestorType;
}
public String getNippinReference() {
return nippinReference;
}
public void setNippinReference(String nippinReference) {
this.nippinReference = nippinReference;
}
}
public class Eattest {
private String invoicingDate;
private String invoicingTime;
private String attestorNihii;
private String providerFeeAmount;
private String entrepriseNumber;
private String receivedNissNumber;
private List<ePrestation> ePrestationList = new ArrayList<>();
public List<ePrestation> getePrestationList() {
return ePrestationList;
}
public void setePrestationList(List<ePrestation> ePrestationList) {
this.ePrestationList = ePrestationList;
}
public String getInvoicingDate() {
return invoicingDate;
}
public void setInvoicingDate(String invoicingDate) {
this.invoicingDate = invoicingDate;
}
public String getInvoicingTime() {
return invoicingTime;
}
public void setInvoicingTime(String invoicingTime) {
this.invoicingTime = invoicingTime;
}
public String getAttestorNihii() {
return attestorNihii;
}
public void setAttestorNihii(String attestorNihii) {
this.attestorNihii = attestorNihii;
}
public String getProviderFeeAmount() {
return providerFeeAmount;
}
public void setProviderFeeAmount(String providerFeeAmount) {
this.providerFeeAmount = providerFeeAmount;
}
public String getEntrepriseNumber() {
return entrepriseNumber;
}
public void setEntrepriseNumber(String entrepriseNumber) {
this.entrepriseNumber = entrepriseNumber;
}
public String getReceivedNissNumber() {
return receivedNissNumber;
}
public void setReceivedNissNumber(String receivedNissNumber) {
this.receivedNissNumber = receivedNissNumber;
}
}
public class ePrestation {
private int order;
private String creationDetailDate;
private String creationDetailTime;
private String providerNihii;
private String prestationCode;
private int quantity;
private String beginDate;
private String endDate;
public int getOrder() {
return order;
}
public void setOrder(int order) {
this.order = order;
}
public String getCreationDetailDate() {
return creationDetailDate;
}
public void setCreationDetailDate(String creationDetailDate) {
this.creationDetailDate = creationDetailDate;
}
public String getCreationDetailTime() {
return creationDetailTime;
}
public void setCreationDetailTime(String creationDetailTime) {
this.creationDetailTime = creationDetailTime;
}
public String getProviderNihii() {
return providerNihii;
}
public void setProviderNihii(String providerNihii) {
this.providerNihii = providerNihii;
}
public String getPrestationCode() {
return prestationCode;
}
public void setPrestationCode(String prestationCode) {
this.prestationCode = prestationCode;
}
public int getQuantity() {
return quantity;
}
public void setQuantity(int quantity) {
this.quantity = quantity;
}
public String getBeginDate() {
return beginDate;
}
public void setBeginDate(String beginDate) {
this.beginDate = beginDate;
}
public String getEndDate() {
return endDate;
}
public void setEndDate(String endDate) {
this.endDate = endDate;
}
}
级别访问它。
screen