将读取设备id和剪贴板权限时机放在用户同意隐私政策之后
This commit is contained in:
parent
fb06ac82d8
commit
ad633d6502
36
App.jsx
36
App.jsx
|
@ -43,6 +43,7 @@ import { save, get, remove, storeAppInfo } from "./utils/storeInfo";
|
|||
import baseRequest from "./utils/baseRequest";
|
||||
import { generateSignature } from "./utils/crypto";
|
||||
import * as Clipboard from "expo-clipboard";
|
||||
import PrivatyModal from "./components/PrivatyModal";
|
||||
|
||||
const RootStack = createNativeStackNavigator();
|
||||
|
||||
|
@ -63,6 +64,23 @@ export default function App() {
|
|||
//保存用户剪贴板内容
|
||||
const [inviterCode, setInviterCode] = useState();
|
||||
|
||||
//未同意用户协议和隐私政策时展示隐私弹窗
|
||||
const [isPrivatyModalOpen, setIsPrivatyModalOpen] = useState(false);
|
||||
//隐私弹窗是否同意
|
||||
const [checked, setChecked] = useState(false);
|
||||
//如果是第一次打开app则展示隐私弹窗
|
||||
useEffect(() => {
|
||||
const handlePrivatyModal = async () => {
|
||||
const notFirstTimeOpenApp = await get("not_first_time_open_app");
|
||||
if (!notFirstTimeOpenApp) {
|
||||
setIsPrivatyModalOpen(true);
|
||||
save("not_first_time_open_app", 1);
|
||||
return;
|
||||
}
|
||||
};
|
||||
handlePrivatyModal();
|
||||
}, []);
|
||||
|
||||
//获取环境变量
|
||||
const apiUrl = process.env.EXPO_PUBLIC_API_URL;
|
||||
//登录逻辑
|
||||
|
@ -106,8 +124,10 @@ export default function App() {
|
|||
}
|
||||
},
|
||||
inviterCode: inviterCode,
|
||||
checked: checked,
|
||||
setChecked: setChecked,
|
||||
}),
|
||||
[inviterCode]
|
||||
[inviterCode, checked]
|
||||
);
|
||||
//控制开屏图片出现
|
||||
const [appIsReady, setAppIsReady] = useState(false);
|
||||
|
@ -117,7 +137,6 @@ export default function App() {
|
|||
const [versionData, setVersionData] = useState({});
|
||||
useEffect(() => {
|
||||
async function prepare() {
|
||||
await storeAppInfo();
|
||||
try {
|
||||
const token = await get("token");
|
||||
const account = await get("account");
|
||||
|
@ -125,6 +144,7 @@ export default function App() {
|
|||
const signature = await generateSignature({
|
||||
...base,
|
||||
});
|
||||
//检查当前token是否有效
|
||||
if (token && account) {
|
||||
const response = await fetch(
|
||||
`${apiUrl}/api/login/validate?signature=${signature}`,
|
||||
|
@ -190,8 +210,10 @@ export default function App() {
|
|||
//当用户未登录时,获取剪贴板内容,用于绑定邀请人
|
||||
useEffect(() => {
|
||||
if (state.isSignin) return;
|
||||
if (!checked) return; //用户未同意隐私政策时不获取剪贴板信息
|
||||
getClipboardContent();
|
||||
}, []);
|
||||
storeAppInfo();
|
||||
}, [checked]);
|
||||
|
||||
//每次从后台切换到前台时,获取用户剪贴板内容
|
||||
const appState = useRef(AppState.currentState);
|
||||
|
@ -551,6 +573,14 @@ export default function App() {
|
|||
status={streamerNavigatorModalStatus}
|
||||
setStatus={setStreamerNavigatorModalStatus}
|
||||
/>
|
||||
<PrivatyModal
|
||||
visible={isPrivatyModalOpen}
|
||||
setVisible={setIsPrivatyModalOpen}
|
||||
confirm={() => {
|
||||
setIsPrivatyModalOpen(false);
|
||||
setChecked(true);
|
||||
}}
|
||||
/>
|
||||
</NavigationContainer>
|
||||
</View>
|
||||
<Toast />
|
||||
|
|
2
app.json
2
app.json
|
@ -2,7 +2,7 @@
|
|||
"expo": {
|
||||
"name": "铁粉空间",
|
||||
"slug": "ironfans",
|
||||
"version": "1.1.4",
|
||||
"version": "1.1.5",
|
||||
"orientation": "portrait",
|
||||
"icon": "./assets/icon.png",
|
||||
"splash": {
|
||||
|
|
|
@ -11,8 +11,8 @@ import MyDivider from "../../../components/MyDivider";
|
|||
import baseRequest from "../../../utils/baseRequest";
|
||||
import { get } from "../../../utils/storeInfo";
|
||||
|
||||
export default function PasswordLogin({ checked, setChecked }) {
|
||||
const { signIn } = useContext(AuthContext);
|
||||
export default function PasswordLogin() {
|
||||
const { signIn, checked, setChecked } = useContext(AuthContext);
|
||||
const navigation = useNavigation();
|
||||
const tailwind = useTailwind();
|
||||
//获取环境变量
|
||||
|
|
|
@ -11,8 +11,8 @@ import baseRequest from "../../../utils/baseRequest";
|
|||
import { get, save } from "../../../utils/storeInfo";
|
||||
import { generateSignature } from "../../../utils/crypto";
|
||||
|
||||
export default function PhoneNumLogin({ checked, setChecked }) {
|
||||
const { signIn, inviterCode } = useContext(AuthContext);
|
||||
export default function PhoneNumLogin() {
|
||||
const { signIn, inviterCode, checked, setChecked } = useContext(AuthContext);
|
||||
const navigation = useNavigation();
|
||||
const tailwind = useTailwind();
|
||||
//设置checkbox
|
||||
|
|
|
@ -10,8 +10,6 @@ import { useSafeAreaInsets } from "react-native-safe-area-context";
|
|||
import { useTailwind } from "tailwind-rn";
|
||||
import PasswordLogin from "./PasswordLogin";
|
||||
import PhoneNumLogin from "./PhoneNumLogin";
|
||||
import PrivatyModal from "../../components/PrivatyModal";
|
||||
import { get, save } from "../../utils/storeInfo";
|
||||
|
||||
export default function Login() {
|
||||
const tailwind = useTailwind();
|
||||
|
@ -23,23 +21,6 @@ export default function Login() {
|
|||
const windowWidth = Dimensions.get("window").width;
|
||||
const tabWidth = windowWidth / 2;
|
||||
|
||||
//未同意用户协议和隐私政策时展示隐私弹窗
|
||||
const [isPrivatyModalOpen, setIsPrivatyModalOpen] = useState(false);
|
||||
const [checked, setChecked] = useState(false);
|
||||
|
||||
//如果是第一次打开app则展示隐私弹窗,如果不是第一次打开app则直接勾选同意协议
|
||||
useEffect(() => {
|
||||
const handlePrivatyModal = async () => {
|
||||
const notFirstTimeOpenApp = await get("not_first_time_open_app");
|
||||
if (!notFirstTimeOpenApp) {
|
||||
setIsPrivatyModalOpen(true);
|
||||
save("not_first_time_open_app", 1);
|
||||
return;
|
||||
}
|
||||
};
|
||||
handlePrivatyModal();
|
||||
}, []);
|
||||
|
||||
return (
|
||||
<TouchableWithoutFeedback onPress={() => Keyboard.dismiss()}>
|
||||
<View
|
||||
|
@ -51,14 +32,6 @@ export default function Login() {
|
|||
...tailwind("flex flex-1"),
|
||||
}}
|
||||
>
|
||||
<PrivatyModal
|
||||
visible={isPrivatyModalOpen}
|
||||
setVisible={setIsPrivatyModalOpen}
|
||||
confirm={() => {
|
||||
setIsPrivatyModalOpen(false);
|
||||
setChecked(true);
|
||||
}}
|
||||
/>
|
||||
{/* tab栏 */}
|
||||
<Tab
|
||||
value={index}
|
||||
|
@ -103,10 +76,10 @@ export default function Login() {
|
|||
disableSwipe
|
||||
>
|
||||
<TabView.Item style={tailwind("w-full flex-1")}>
|
||||
<PhoneNumLogin checked={checked} setChecked={setChecked} />
|
||||
<PhoneNumLogin />
|
||||
</TabView.Item>
|
||||
<TabView.Item style={tailwind("w-full flex-1")}>
|
||||
<PasswordLogin checked={checked} setChecked={setChecked} />
|
||||
<PasswordLogin />
|
||||
</TabView.Item>
|
||||
</TabView>
|
||||
</View>
|
||||
|
|
Loading…
Reference in New Issue