Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

330
Views
Restringir la aplicación para que no regrese a través de react-native-webview (React Native)

Desarrollé un sitio web usando reaccionar y ahora he estado tratando de usar esto a través de webview en reaccionar nativo.

Problema: cuando uso el botón Atrás, la aplicación se cierra.

Razón:

  • En mi sitio web de React, estoy usando Link {from react-router dom} para que la navegación no se agregue en el historial.
  • En React Native, dado que onNavigationStateChange usa el historial, navState.canGoBack() devuelve falso.

¿Qué puedo incluir en este else block in handleBackButton para que la aplicación no se cierre?

 import React, { Component } from "react"; import { SafeAreaView, Platform, StatusBar } from "react-native"; import { BackHandler } from "react-native"; import { WebView } from "react-native-webview"; export default class Marketplace extends Component { constructor(props) { super(props); this.state = { canGoBack: false, } } WEBVIEW_REF = React.createRef(); componentDidMount() { BackHandler.addEventListener("hardwareBackPress", this.handleBackButton); } componentWillUnmount() { BackHandler.removeEventListener("hardwareBackPress", this.handleBackButton); } handleBackButton = () => { if (this.state.canGoBack) { this.WEBVIEW_REF.current.goBack(); return true; } else { console.log("Else block"); // what to add here to restrict the app to exit } }; onNavigationStateChange = (navState) => { console.log("navState", navState.canGoBack); this.setState({ canGoBack: navState.canGoBack, }); }; render() { return ( <SafeAreaView style={{ flex: 1, paddingTop: Platform.OS === "android" ? StatusBar.currentHeight : 0, }} > <WebView source={{ uri: "http://localhost:3000/", }} ref={this.WEBVIEW_REF} onNavigationStateChange={this.onNavigationStateChange} /> </SafeAreaView> ); } }
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

si desea impedir que el usuario salga de la aplicación, también tendrá que devolver verdadero en la declaración else o simplemente puede hacer esto:

 handleBackButton = () => { if (this.state.canGoBack) { this.WEBVIEW_REF.current.goBack(); } return true; }
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!