AsyncStorage→ReactNativeStorageへの変更
This commit is contained in:
parent
29963ab876
commit
1a1227dfeb
28
Apps.js
28
Apps.js
@ -8,7 +8,7 @@ import {
|
||||
} from "react-native";
|
||||
import { WebView } from "react-native-webview";
|
||||
import Constants from "expo-constants";
|
||||
import AsyncStorage from "@react-native-async-storage/async-storage";
|
||||
import { AS } from "./storageControl";
|
||||
import { news } from "./config/newsUpdate";
|
||||
import { getStationList, lineList } from "./lib/getStationList";
|
||||
import { StationDeteilView } from "./components/ActionSheetComponents/StationDeteilView";
|
||||
@ -53,7 +53,7 @@ export default function Apps(props) {
|
||||
|
||||
useEffect(() => {
|
||||
//ニュース表示
|
||||
AsyncStorage.getItem("status")
|
||||
AS.getItem("status")
|
||||
.then((d) => {
|
||||
if (d != news) navigate("news");
|
||||
})
|
||||
@ -62,48 +62,42 @@ export default function Apps(props) {
|
||||
|
||||
useEffect(() => {
|
||||
//列車アイコンスイッチ
|
||||
AsyncStorage.getItem("iconSwitch")
|
||||
AS.getItem("iconSwitch")
|
||||
.then((d) => {
|
||||
if (d) {
|
||||
setIconSetting(d);
|
||||
} else {
|
||||
AsyncStorage.setItem("iconSwitch", "true").then(Updates.reloadAsync);
|
||||
AS.setItem("iconSwitch", "true").then(Updates.reloadAsync);
|
||||
}
|
||||
})
|
||||
.catch((d) =>
|
||||
AsyncStorage.setItem("iconSwitch", "true").then(Updates.reloadAsync)
|
||||
);
|
||||
.catch((d) => AS.setItem("iconSwitch", "true").then(Updates.reloadAsync));
|
||||
}, []);
|
||||
|
||||
useEffect(() => {
|
||||
//地図スイッチ
|
||||
AsyncStorage.getItem("mapSwitch")
|
||||
AS.getItem("mapSwitch")
|
||||
.then((d) => {
|
||||
if (d) {
|
||||
setMapSwitch(d);
|
||||
} else {
|
||||
AsyncStorage.setItem("mapSwitch", "false").then(Updates.reloadAsync);
|
||||
AS.setItem("mapSwitch", "false").then(Updates.reloadAsync);
|
||||
}
|
||||
})
|
||||
.catch((d) =>
|
||||
AsyncStorage.setItem("mapSwitch", "false").then(Updates.reloadAsync)
|
||||
);
|
||||
.catch((d) => AS.setItem("mapSwitch", "false").then(Updates.reloadAsync));
|
||||
}, []);
|
||||
|
||||
useEffect(() => {
|
||||
//駅メニュースイッチ
|
||||
AsyncStorage.getItem("stationSwitch")
|
||||
AS.getItem("stationSwitch")
|
||||
.then((d) => {
|
||||
if (d) {
|
||||
setStationMenu(d);
|
||||
} else {
|
||||
AsyncStorage.setItem("stationSwitch", "true").then(
|
||||
Updates.reloadAsync
|
||||
);
|
||||
AS.setItem("stationSwitch", "true").then(Updates.reloadAsync);
|
||||
}
|
||||
})
|
||||
.catch((d) =>
|
||||
AsyncStorage.setItem("stationSwitch", "true").then(Updates.reloadAsync)
|
||||
AS.setItem("stationSwitch", "true").then(Updates.reloadAsync)
|
||||
);
|
||||
}, []);
|
||||
|
||||
|
@ -2,7 +2,7 @@ import React from "react";
|
||||
import { View, Text, TouchableOpacity } from "react-native";
|
||||
import { WebView } from "react-native-webview";
|
||||
import StatusbarDetect from "../StatusbarDetect";
|
||||
import AsyncStorage from "@react-native-async-storage/async-storage";
|
||||
import { AS } from "../storageControl";
|
||||
import { news } from "../config/newsUpdate";
|
||||
var Status = StatusbarDetect();
|
||||
export default function News(props) {
|
||||
@ -30,7 +30,7 @@ export default function News(props) {
|
||||
alignItems: "center",
|
||||
}}
|
||||
onPress={() => {
|
||||
AsyncStorage.setItem("status", news);
|
||||
AS.setItem("status", news);
|
||||
navigate("Apps");
|
||||
}}
|
||||
>
|
||||
|
@ -2,7 +2,7 @@ import React, { useState, useEffect } from "react";
|
||||
import { View, Text, TouchableOpacity } from "react-native";
|
||||
import * as Updates from "expo-updates";
|
||||
import StatusbarDetect from "../StatusbarDetect";
|
||||
import AsyncStorage from "@react-native-async-storage/async-storage";
|
||||
import { AS } from "../storageControl";
|
||||
var Status = StatusbarDetect();
|
||||
import { Switch } from "react-native-elements";
|
||||
|
||||
@ -14,9 +14,9 @@ export default function Setting(props) {
|
||||
const [mapSwitch, setMapSwitch] = useState(undefined);
|
||||
const [stationMenu, setStationMenu] = useState(undefined);
|
||||
useEffect(() => {
|
||||
AsyncStorage.getItem("iconSwitch").then(setIconSetting);
|
||||
AsyncStorage.getItem("mapSwitch").then(setMapSwitch);
|
||||
AsyncStorage.getItem("stationSwitch").then(setStationMenu);
|
||||
AS.getItem("iconSwitch").then(setIconSetting);
|
||||
AS.getItem("mapSwitch").then(setMapSwitch);
|
||||
AS.getItem("stationSwitch").then(setStationMenu);
|
||||
}, []);
|
||||
return (
|
||||
<View style={{ height: "100%", backgroundColor: "#0099CC" }}>
|
||||
@ -134,9 +134,9 @@ export default function Setting(props) {
|
||||
}}
|
||||
onPress={() => {
|
||||
Promise.all([
|
||||
AsyncStorage.setItem("iconSwitch", iconSetting.toString()),
|
||||
AsyncStorage.setItem("mapSwitch", mapSwitch.toString()),
|
||||
AsyncStorage.setItem("stationSwitch", stationMenu.toString()),
|
||||
AS.setItem("iconSwitch", iconSetting.toString()),
|
||||
AS.setItem("mapSwitch", mapSwitch.toString()),
|
||||
AS.setItem("stationSwitch", stationMenu.toString()),
|
||||
]).then(() => {
|
||||
Updates.reloadAsync();
|
||||
});
|
||||
|
@ -1,6 +1,5 @@
|
||||
import React, { useRef } from "react";
|
||||
import { View, Text, TouchableOpacity, Linking } from "react-native";
|
||||
import AsyncStorage from "@react-native-async-storage/async-storage";
|
||||
import MapView, { Marker } from "react-native-maps";
|
||||
import { MaterialCommunityIcons } from "@expo/vector-icons";
|
||||
export default function trainMenu({
|
||||
@ -101,7 +100,6 @@ export default function trainMenu({
|
||||
alignItems: "center",
|
||||
}}
|
||||
onPress={() => {
|
||||
AsyncStorage.setItem("status", "2022/04/14");
|
||||
navigate("Apps");
|
||||
}}
|
||||
>
|
||||
|
27
storageConfig.js
Normal file
27
storageConfig.js
Normal file
@ -0,0 +1,27 @@
|
||||
import Storage from "react-native-storage";
|
||||
import AsyncStorage from "@react-native-async-storage/async-storage";
|
||||
|
||||
const storage = new Storage({
|
||||
// maximum capacity, default 1000 key-ids
|
||||
size: 10000,
|
||||
|
||||
// Use AsyncStorage for RN apps, or window.localStorage for web apps.
|
||||
// If storageBackend is not set, data will be lost after reload.
|
||||
storageBackend: AsyncStorage, // for web: window.localStorage
|
||||
|
||||
// expire time, default: 1 day (1000 * 3600 * 24 milliseconds).
|
||||
// can be null, which means never expire.
|
||||
defaultExpires: null,
|
||||
|
||||
// cache data in the memory. default is true.
|
||||
enableCache: true,
|
||||
|
||||
// if data was not found in storage or expired data was found,
|
||||
// the corresponding sync method will be invoked returning
|
||||
// the latest data.
|
||||
sync: {
|
||||
// we'll talk about the details later.
|
||||
},
|
||||
});
|
||||
|
||||
export default storage;
|
14
storageControl.js
Normal file
14
storageControl.js
Normal file
@ -0,0 +1,14 @@
|
||||
import storage from "./storageConfig.js";
|
||||
|
||||
export const AS = {
|
||||
getItem: (key) => storage.load({ key }),
|
||||
setItem: (key, data) =>
|
||||
storage.save({
|
||||
key, // Note: Do not use underscore("_") in key!
|
||||
data,
|
||||
|
||||
// if expires not specified, the defaultExpires will be applied instead.
|
||||
// if set to null, then it will never expire.
|
||||
expires: null,
|
||||
}),
|
||||
};
|
Loading…
Reference in New Issue
Block a user