微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

使用WebView更改默认页面时如何进行条件渲染TouchableOpacity?

如何解决使用WebView更改默认页面时如何进行条件渲染TouchableOpacity?

使用WebView更改页面时如何进行条件渲染?我想呈现一个 TouchableOpacity 组件以作为后退按钮呈现给用户,只有在用户单击第二页的链接并返回上一页之后。


My NavigationView.js

import * as React from 'react';
import { View,StyleSheet,TouchableOpacity,Animated } from 'react-native';
import { AntDesign} from "@expo/vector-icons";


const NavigationView = ({ onBackPress }) => (
<View style={[styles.container2]}>
        <TouchableOpacity style={[ styles.container2,styles.button,styles.menu]} onPress={onBackPress}>
          <Animated.View>
            <AntDesign name="back"size={28} color="#fff"/>
          </Animated.View>
        </TouchableOpacity>
  </View>
);

const styles = StyleSheet.create({
  container2: {
    alignItems: 'flex-start',justifyContent: 'flex-end',marginHorizontal:3,marginVertical: 2,},title: {
    fontSize: 20,fontWeight: 'bold',separator: {
    marginVertical: 30,height: 1,width: '80%',button: {
    position: "absolute",width: 55,height: 55,borderRadius: 55 / 2,alignItems: "center",justifyContent: "center",shadowRadius: 10,shadowColor: "#2f95dc",shadowOpacity: 0.3,shadowOffset: { height: 10}    
  },menu : { 
    backgroundColor: "#2f95dc",}
});

export default NavigationView;

如何使用 webview 使后退按钮仅在用户走到下一页后才出现。当用户返回到初始 webview 中呈现的页面时,该按钮将再次隐藏。


My TabAtualidadesScreen.js

import * as React from 'react';
import { WebView } from 'react-native-webview';
import { useState,useEffect,useRef,Component} from 'react';
import {Text,View } from '../components/Themed';
import * as Progress from 'react-native-progress';
import NavigationView from '../navigation/NavigationView';
import { isLoading } from 'expo-font';


const TabAtualidadesScreen = () => {

  const [progress,setProgress] = useState(0);
  const [isLoaded,setLoaded] = useState(false);

  const webViewRef = useRef();
  const [canGoBack,setCanGoBack] = useState(false);

  const handleBackPress = () => {
    webViewRef.current.goBack();
  }

  
  return <>
  {
    !isLoaded ?
    <Progress.Bar 
    borderWidth={0}s
    borderRadius={0}
    color='#2778a3'
    progress={progress} 
    width={null} 
    />
    : null
  }
 
  <WebView
    ref={webViewRef}
    source={{ uri: 'yourInitialUrl' }} 
    
    onLoadEnd={() => setLoaded(true) }
    onLoadProgress={({nativeEvent}) => setProgress(nativeEvent.progress)}

    onNavigationStateChange={(state) => {
      const back = state.canGoBack;
      setCanGoBack(back);

      setWebViewUrlChanged = webviewState => {
        if (webviewState.url !== yourInitialUrl) {
          this.setState({ isWebViewUrlChanged: true });
          {<NavigationView onBackPress={handleBackPress}/>}
        }
      };
    }}
    
  />
  
</>
}

export default TabAtualidadesScreen;

使用WebView更改页面时如何进行条件渲染?我想呈现一个 TouchableOpacity 组件以作为后退按钮呈现给用户,只有在用户单击第二页的链接并返回上一页之后。

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。