How to call two function on onpress event in react native?
In below code, I want to call both methods on onpress
event but I'm facing some issues, please give some idea how to call two methods on onpress event.
One method for start chatting and second for changing images on onpress event. Thank you
chatStart = () => {
var { msg } = this.state;
var { o_code } = this.state;
var ucod = o_code;
//console.log(o_code);
var { session } = this.state;
//console.log(session);
var { ocod } = this.state;
//console.log(ocod);
var { Name } = this.state;
var user_name = Name;
var request = new XMLHttpRequest();
request.onreadystatechange = e => {
if (request.readyState !== 4) {
return;
}
if (request.status === 200) {
console.log("success", request.responseText);
} else {
console.warn("error");
}
};
// var msg = "good things take some time";
console.log(user_name);
request.open(
"POST",
"http://www.aonde.biz/mobile/getChat.php?ocod=" +
ocod +
"&ucod=" +
ucod +
"&session=" +
session,
true
);
request.setRequestHeader(
"Content-type",
"application/x-www-form-urlencoded"
);
request.send("message=" + msg + "&name=" + user_name + "&ocod=" + ocod);
};
changeImage = () => {
console.log("state changed!");
this.setState({
uri: require("./35-reject-red.png")
});
};
<View>
<TouchableOpacity activeOpacity={0.5} onPress={this.changeImage}>
<Image source={this.state.uri} />
</TouchableOpacity>
</View>
javascript android reactjs react-native
|
show 3 more comments
In below code, I want to call both methods on onpress
event but I'm facing some issues, please give some idea how to call two methods on onpress event.
One method for start chatting and second for changing images on onpress event. Thank you
chatStart = () => {
var { msg } = this.state;
var { o_code } = this.state;
var ucod = o_code;
//console.log(o_code);
var { session } = this.state;
//console.log(session);
var { ocod } = this.state;
//console.log(ocod);
var { Name } = this.state;
var user_name = Name;
var request = new XMLHttpRequest();
request.onreadystatechange = e => {
if (request.readyState !== 4) {
return;
}
if (request.status === 200) {
console.log("success", request.responseText);
} else {
console.warn("error");
}
};
// var msg = "good things take some time";
console.log(user_name);
request.open(
"POST",
"http://www.aonde.biz/mobile/getChat.php?ocod=" +
ocod +
"&ucod=" +
ucod +
"&session=" +
session,
true
);
request.setRequestHeader(
"Content-type",
"application/x-www-form-urlencoded"
);
request.send("message=" + msg + "&name=" + user_name + "&ocod=" + ocod);
};
changeImage = () => {
console.log("state changed!");
this.setState({
uri: require("./35-reject-red.png")
});
};
<View>
<TouchableOpacity activeOpacity={0.5} onPress={this.changeImage}>
<Image source={this.state.uri} />
</TouchableOpacity>
</View>
javascript android reactjs react-native
1
but faces some issue
don't you want to tell us which issue?
– Vladyslav Matviienko
Nov 13 '18 at 7:05
calling both methods on onpress event related issue thanks
– Atul Tiwari
Nov 13 '18 at 7:10
I don't see you are trying to do something onpress at all
– Vladyslav Matviienko
Nov 13 '18 at 7:11
<View> <TouchableOpacity activeOpacity={0.5} onPress={this.changeImage}> <Image source={this.state.uri} /> </TouchableOpacity> </View>
– Atul Tiwari
Nov 13 '18 at 7:13
ok, just create 1 more function, in which call both functions that you want to call onpress, and call this new function onpress
– Vladyslav Matviienko
Nov 13 '18 at 7:14
|
show 3 more comments
In below code, I want to call both methods on onpress
event but I'm facing some issues, please give some idea how to call two methods on onpress event.
One method for start chatting and second for changing images on onpress event. Thank you
chatStart = () => {
var { msg } = this.state;
var { o_code } = this.state;
var ucod = o_code;
//console.log(o_code);
var { session } = this.state;
//console.log(session);
var { ocod } = this.state;
//console.log(ocod);
var { Name } = this.state;
var user_name = Name;
var request = new XMLHttpRequest();
request.onreadystatechange = e => {
if (request.readyState !== 4) {
return;
}
if (request.status === 200) {
console.log("success", request.responseText);
} else {
console.warn("error");
}
};
// var msg = "good things take some time";
console.log(user_name);
request.open(
"POST",
"http://www.aonde.biz/mobile/getChat.php?ocod=" +
ocod +
"&ucod=" +
ucod +
"&session=" +
session,
true
);
request.setRequestHeader(
"Content-type",
"application/x-www-form-urlencoded"
);
request.send("message=" + msg + "&name=" + user_name + "&ocod=" + ocod);
};
changeImage = () => {
console.log("state changed!");
this.setState({
uri: require("./35-reject-red.png")
});
};
<View>
<TouchableOpacity activeOpacity={0.5} onPress={this.changeImage}>
<Image source={this.state.uri} />
</TouchableOpacity>
</View>
javascript android reactjs react-native
In below code, I want to call both methods on onpress
event but I'm facing some issues, please give some idea how to call two methods on onpress event.
One method for start chatting and second for changing images on onpress event. Thank you
chatStart = () => {
var { msg } = this.state;
var { o_code } = this.state;
var ucod = o_code;
//console.log(o_code);
var { session } = this.state;
//console.log(session);
var { ocod } = this.state;
//console.log(ocod);
var { Name } = this.state;
var user_name = Name;
var request = new XMLHttpRequest();
request.onreadystatechange = e => {
if (request.readyState !== 4) {
return;
}
if (request.status === 200) {
console.log("success", request.responseText);
} else {
console.warn("error");
}
};
// var msg = "good things take some time";
console.log(user_name);
request.open(
"POST",
"http://www.aonde.biz/mobile/getChat.php?ocod=" +
ocod +
"&ucod=" +
ucod +
"&session=" +
session,
true
);
request.setRequestHeader(
"Content-type",
"application/x-www-form-urlencoded"
);
request.send("message=" + msg + "&name=" + user_name + "&ocod=" + ocod);
};
changeImage = () => {
console.log("state changed!");
this.setState({
uri: require("./35-reject-red.png")
});
};
<View>
<TouchableOpacity activeOpacity={0.5} onPress={this.changeImage}>
<Image source={this.state.uri} />
</TouchableOpacity>
</View>
javascript android reactjs react-native
javascript android reactjs react-native
edited Nov 13 '18 at 7:58
c-chavez
2,14421733
2,14421733
asked Nov 13 '18 at 7:04
Atul TiwariAtul Tiwari
335
335
1
but faces some issue
don't you want to tell us which issue?
– Vladyslav Matviienko
Nov 13 '18 at 7:05
calling both methods on onpress event related issue thanks
– Atul Tiwari
Nov 13 '18 at 7:10
I don't see you are trying to do something onpress at all
– Vladyslav Matviienko
Nov 13 '18 at 7:11
<View> <TouchableOpacity activeOpacity={0.5} onPress={this.changeImage}> <Image source={this.state.uri} /> </TouchableOpacity> </View>
– Atul Tiwari
Nov 13 '18 at 7:13
ok, just create 1 more function, in which call both functions that you want to call onpress, and call this new function onpress
– Vladyslav Matviienko
Nov 13 '18 at 7:14
|
show 3 more comments
1
but faces some issue
don't you want to tell us which issue?
– Vladyslav Matviienko
Nov 13 '18 at 7:05
calling both methods on onpress event related issue thanks
– Atul Tiwari
Nov 13 '18 at 7:10
I don't see you are trying to do something onpress at all
– Vladyslav Matviienko
Nov 13 '18 at 7:11
<View> <TouchableOpacity activeOpacity={0.5} onPress={this.changeImage}> <Image source={this.state.uri} /> </TouchableOpacity> </View>
– Atul Tiwari
Nov 13 '18 at 7:13
ok, just create 1 more function, in which call both functions that you want to call onpress, and call this new function onpress
– Vladyslav Matviienko
Nov 13 '18 at 7:14
1
1
but faces some issue
don't you want to tell us which issue?– Vladyslav Matviienko
Nov 13 '18 at 7:05
but faces some issue
don't you want to tell us which issue?– Vladyslav Matviienko
Nov 13 '18 at 7:05
calling both methods on onpress event related issue thanks
– Atul Tiwari
Nov 13 '18 at 7:10
calling both methods on onpress event related issue thanks
– Atul Tiwari
Nov 13 '18 at 7:10
I don't see you are trying to do something onpress at all
– Vladyslav Matviienko
Nov 13 '18 at 7:11
I don't see you are trying to do something onpress at all
– Vladyslav Matviienko
Nov 13 '18 at 7:11
<View> <TouchableOpacity activeOpacity={0.5} onPress={this.changeImage}> <Image source={this.state.uri} /> </TouchableOpacity> </View>
– Atul Tiwari
Nov 13 '18 at 7:13
<View> <TouchableOpacity activeOpacity={0.5} onPress={this.changeImage}> <Image source={this.state.uri} /> </TouchableOpacity> </View>
– Atul Tiwari
Nov 13 '18 at 7:13
ok, just create 1 more function, in which call both functions that you want to call onpress, and call this new function onpress
– Vladyslav Matviienko
Nov 13 '18 at 7:14
ok, just create 1 more function, in which call both functions that you want to call onpress, and call this new function onpress
– Vladyslav Matviienko
Nov 13 '18 at 7:14
|
show 3 more comments
2 Answers
2
active
oldest
votes
To call multiple functions on onPress, separate the calls with semicolons, like:
onPress{() => { this.functionOne(); this.functionTwo(); }
add a comment |
Merge two functions that you want to call in one function and give name like 'onPressBlaBlaButton'. And in the render method call this function.
<View>
<TouchableOpacity
activeOpacity={0.5}
onPress={this.onPressBlaBlaButton}>
<Image source={this.state.uri} />
</TouchableOpacity>
</View>
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53275546%2fhow-to-call-two-function-on-onpress-event-in-react-native%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
To call multiple functions on onPress, separate the calls with semicolons, like:
onPress{() => { this.functionOne(); this.functionTwo(); }
add a comment |
To call multiple functions on onPress, separate the calls with semicolons, like:
onPress{() => { this.functionOne(); this.functionTwo(); }
add a comment |
To call multiple functions on onPress, separate the calls with semicolons, like:
onPress{() => { this.functionOne(); this.functionTwo(); }
To call multiple functions on onPress, separate the calls with semicolons, like:
onPress{() => { this.functionOne(); this.functionTwo(); }
answered Nov 13 '18 at 8:21
MachalvanMachalvan
263
263
add a comment |
add a comment |
Merge two functions that you want to call in one function and give name like 'onPressBlaBlaButton'. And in the render method call this function.
<View>
<TouchableOpacity
activeOpacity={0.5}
onPress={this.onPressBlaBlaButton}>
<Image source={this.state.uri} />
</TouchableOpacity>
</View>
add a comment |
Merge two functions that you want to call in one function and give name like 'onPressBlaBlaButton'. And in the render method call this function.
<View>
<TouchableOpacity
activeOpacity={0.5}
onPress={this.onPressBlaBlaButton}>
<Image source={this.state.uri} />
</TouchableOpacity>
</View>
add a comment |
Merge two functions that you want to call in one function and give name like 'onPressBlaBlaButton'. And in the render method call this function.
<View>
<TouchableOpacity
activeOpacity={0.5}
onPress={this.onPressBlaBlaButton}>
<Image source={this.state.uri} />
</TouchableOpacity>
</View>
Merge two functions that you want to call in one function and give name like 'onPressBlaBlaButton'. And in the render method call this function.
<View>
<TouchableOpacity
activeOpacity={0.5}
onPress={this.onPressBlaBlaButton}>
<Image source={this.state.uri} />
</TouchableOpacity>
</View>
answered Nov 13 '18 at 8:35
VolkanSahin45VolkanSahin45
1,325616
1,325616
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53275546%2fhow-to-call-two-function-on-onpress-event-in-react-native%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
1
but faces some issue
don't you want to tell us which issue?– Vladyslav Matviienko
Nov 13 '18 at 7:05
calling both methods on onpress event related issue thanks
– Atul Tiwari
Nov 13 '18 at 7:10
I don't see you are trying to do something onpress at all
– Vladyslav Matviienko
Nov 13 '18 at 7:11
<View> <TouchableOpacity activeOpacity={0.5} onPress={this.changeImage}> <Image source={this.state.uri} /> </TouchableOpacity> </View>
– Atul Tiwari
Nov 13 '18 at 7:13
ok, just create 1 more function, in which call both functions that you want to call onpress, and call this new function onpress
– Vladyslav Matviienko
Nov 13 '18 at 7:14