Please provide the following:
- SDK Version: 46.0.0
- Platforms(Android/iOS/web/all): Android
- Add the appropriate “Tag” based on what Expo library you have a question on.
Hi All,
I have been struggling with this for some time now.
I call the following function from my native return code :
<Text style={[styles.Progress,{fontSize:20}]}>
{calcSessionTime(TrainingPassID)} min.
</Text>
Code :
function calcSessionTime(TrainingPassID){
let time=0;
userDatabase.transaction((tx) => {
tx.executeSql('SELECT sum(TrainingSession.SessionTime)/60 as sessiontime
FROM TrainingSession WHERE TrainingSession.TrainingPassID=?',
[TrainingPassID],(_, { rows: { _array } }) => {
console.log("Sessiontime :" + _array[0].sessiontime);
time = _array[0].sessiontime;
return time;
}
);
});
console.log("return : " + time);
return time;
};
I query a SQLIte database, which return an array with the sessiontime.
I have defined a variable “time” which is intially set to “cero”. This variable is assigned the Result from the query.
For some reason the returned value is still the initial value ???
I have tried to print the “time” out and it seems to be correct but not when the return line is reached ???
Output :
return : 0
Sessiontime : 6
It seems that callback is running as a async function, because the “return” value comes before the “sessiontime” value.
I have tried to figure out how it is possible to wait for the callback but is loost ???
How can this be done ?