我想在本机应用程序上锁屏并在屏幕加载前检查密码
I want lockscreen on react native application and check passwords before screen load
我将应用程序密码存储在应用程序的本地存储中,我只想在 App.js
屏幕呈现之前检查密码
var passwords = null;
function get_passwords() {
// fetch the user defined settings
var db = openDatabase({ name: 'trans_DB.db', createFromLocation: '~www/test_Db.db' });
//to read currency
db.transaction((tx) => {
tx.executeSql(
'SELECT * FROM password_table', [],
(tx, results) => {
var len = results.rows.length;
if (len > 0) {
passwords = results.rows.item(0).passwords
}
}
);
});
}
function App(){
get_passwords();
if(passwords == null){
return lockScreen(); //contains lockscreen
}
else{
return mainScreen(); //if user didn't set the security to app then render main screen
}
}
我试过了,但问题是数据库 returns 在从数据库获取值之前,值延迟和屏幕首先加载
您可以在从数据库检索后的状态下设置密码
import React, { useState, useEffect } from 'react';
function App(){
const [passwords, setPasswords] = useState("");
// set password
useEffect(() => {
get_passwords()
},[]);
const get_passwords = () => {
// fetch the user defined settings
var db = openDatabase({
name: "trans_DB.db",
createFromLocation: "~www/test_Db.db",
});
//to read currency
db.transaction(tx => {
tx.executeSql("SELECT * FROM password_table", [], (tx, results) => {
var len = results.rows.length;
if (len > 0) {
passwords = results.rows.item(0).passwords;
setPasswords(passwords)
}
});
});
};
if(passwords == ""){
return lockScreen(); //contains lockscreen
}
else{
return mainScreen(); //if user didn't set the security to app then render main screen
}
}
我将应用程序密码存储在应用程序的本地存储中,我只想在 App.js
屏幕呈现之前检查密码var passwords = null;
function get_passwords() {
// fetch the user defined settings
var db = openDatabase({ name: 'trans_DB.db', createFromLocation: '~www/test_Db.db' });
//to read currency
db.transaction((tx) => {
tx.executeSql(
'SELECT * FROM password_table', [],
(tx, results) => {
var len = results.rows.length;
if (len > 0) {
passwords = results.rows.item(0).passwords
}
}
);
});
}
function App(){
get_passwords();
if(passwords == null){
return lockScreen(); //contains lockscreen
}
else{
return mainScreen(); //if user didn't set the security to app then render main screen
}
}
我试过了,但问题是数据库 returns 在从数据库获取值之前,值延迟和屏幕首先加载
您可以在从数据库检索后的状态下设置密码
import React, { useState, useEffect } from 'react';
function App(){
const [passwords, setPasswords] = useState("");
// set password
useEffect(() => {
get_passwords()
},[]);
const get_passwords = () => {
// fetch the user defined settings
var db = openDatabase({
name: "trans_DB.db",
createFromLocation: "~www/test_Db.db",
});
//to read currency
db.transaction(tx => {
tx.executeSql("SELECT * FROM password_table", [], (tx, results) => {
var len = results.rows.length;
if (len > 0) {
passwords = results.rows.item(0).passwords;
setPasswords(passwords)
}
});
});
};
if(passwords == ""){
return lockScreen(); //contains lockscreen
}
else{
return mainScreen(); //if user didn't set the security to app then render main screen
}
}