I follow all instructions for installing React Navigation for Android.
First, "npm install --save react-navigation", " npm install --save react-native-gesture-handler". "react-native link react-native-gesture-handler" and lastly, updated my MainActivity.java
Here is my MainActivity.java:
import com.facebook.react.ReactActivity;
import com.facebook.react.ReactActivityDelegate;
import com.facebook.react.ReactRootView;
import com.swmansion.gesturehandler.react.RNGestureHandlerEnabledRootView;
public class MainActivity extends ReactActivity {
/**
* Returns the name of the main component registered from JavaScript.
* This is used to schedule rendering of the component.
*/
#Override
protected String getMainComponentName() {
return "InstagramClone";
}
#Override
protected ReactActivityDelegate createReactActivityDelegate() {
return new ReactActivityDelegate(this, getMainComponentName()) {
#Override
protected ReactRootView createRootView() {
return new RNGestureHandlerEnabledRootView(MainActivity.this)
}
};
}
}
This is the error I got:
What went wrong:
Failed to create parent directory 'D:\React Native Projects\InstagramClone\node_modules\react-native-gesture-handler\android\build' when creating directory 'D:\React Native Projects\InstagramClone\node_modules\react-native-gesture-handler\android\build\intermediates\check-manifest\debug'
If you initiated your project with expo just install react-native-gesture-handler. But if your projected started by react-native cli you have to first install react-native-gesture-handler and then link it to all packages by the command:
react-native link
if you had to a link react-native-gesture-handler there should be no problem or you try react-native link it will be link all package. Or if you still face same problem delete app first on your emulator then React-native run-android again
You need to install react-native-gesture-handler npm separately. They create separated npm package for touch & gesture handling and recognition.
Step 1.
npm i react-native-gesture-handler
Step 2.
react-native link react-native-gesture-handler
Step 3.(optional )
If step 2 is not worked properly, code is not configured properly so we are manually configure it using step 3
To finalize the installation of react-native-gesture-handler for Android, be sure to make the necessary modifications to MainActivity.java:
import com.facebook.react.ReactActivity; import com.facebook.react.ReactActivityDelegate; import com.facebook.react.ReactRootView; import
com.swmansion.gesturehandler.react.RNGestureHandlerEnabledRootView;
public class MainActivity extends ReactActivity {
#Override protected
String getMainComponentName() { return "Example"; }
#Override
protected ReactActivityDelegate createReactActivityDelegate() {
return new ReactActivityDelegate(this, getMainComponentName()) {
#Override
protected ReactRootView createRootView() {
return new RNGestureHandlerEnabledRootView(MainActivity.this); }
};
} }
No additional steps are required for iOS.
Please Refer the following document for more information:-
https://reactnavigation.org/docs/en/getting-started.html#installation
https://www.npmjs.com/package/react-native-gesture-handler/v/1.0.0-alpha.34?activeTab=readme
https://kmagiera.github.io/react-native-gesture-handler/docs/getting-started.html
Related
We have a React Native app which shows our mobile website and adds some extra features.
Since Android 12 App links (like domain.com) always open our app: https://developer.android.com/training/app-links
This behaviour is not always desirable, for example in this scenario:
Customer is logged in and starts an order via their browser
Customer needs to pay via an app from their bank
After payment, the customer is redirected back to our website (domain.com/returnUrl)
Now the app is opened, instead of the browser, so the customer isn't logged-in and isn't allowed to view the page.
In this case, after payment started from the browser, we would like to redirect the customer back to the browser instead of the app.
Is there a way to open a link in the browser (ie. via domain.com/returnUrl?force-browser) instead of the app?
Related: Android App link - Open a url from app in browser without triggering App Link
Based on this answer, I've created a RN Native Module and instead of using await Linking.openURL(url) you can just use the Native Module's exposed method to open Android App links.
I've followed the official RN tutorial to make an Android Native Module.
So in summary, first you will have to create a Java class file inside android/app/src/main/java/com/your-app-name/folder. I've named the module DefaultBrowserModule so the path is src/main/java/com/your-app-name/DefaultBrowserModule.java. Here's how it looks like:
package com.your-app-name;
import android.content.Intent;
import android.net.Uri;
import androidx.annotation.NonNull;
import com.facebook.react.bridge.ReactApplicationContext;
import com.facebook.react.bridge.ReactContextBaseJavaModule;
import com.facebook.react.bridge.ReactMethod;
public class DefaultBrowserModule extends ReactContextBaseJavaModule {
private ReactApplicationContext _context;
DefaultBrowserModule(ReactApplicationContext context) {
super(context);
this._context = context;
}
#NonNull
#Override
public String getName() {
return "DefaultBrowserModule";
}
// This is the method that we're exposing
#ReactMethod
public void openUrl(String url) {
Intent defaultBrowser = Intent.makeMainSelectorActivity(Intent.ACTION_MAIN, Intent.CATEGORY_APP_BROWSER);
defaultBrowser.setData(Uri.parse(url));
// Through ReactApplicationContext's current activty, start a new activity
this._context.getCurrentActivity().startActivity(defaultBrowser);
}
}
After that we'll have to register the module with React Native. That can be done by adding a new Java class file to the android/app/src/main/java/com/your-app-name/ folder. I've named mine DefaultBrowserPackage: src/main/java/com/your-app-name/DefaultBrowserPackage.java:
package com.your-app-name;
import androidx.annotation.NonNull;
import com.facebook.react.ReactPackage;
import com.facebook.react.bridge.NativeModule;
import com.facebook.react.bridge.ReactApplicationContext;
import com.facebook.react.uimanager.ViewManager;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
public class DefaultBrowserPackage implements ReactPackage {
#NonNull
#Override
public List<NativeModule> createNativeModules(#NonNull ReactApplicationContext reactContext) {
List<NativeModule> modules = new ArrayList<>();
modules.add(new DefaultBrowserModule(reactContext));
return modules;
}
#NonNull
#Override
public List<ViewManager> createViewManagers(#NonNull ReactApplicationContext reactContext) {
return Collections.emptyList();
}
}
The last step is to register the DefaultBrowserPackage inside of MainApplication.java (android/app/src/main/java/com/your-app-name/MainApplication.java). Locate ReactNativeHost’s getPackages() method and add your package to the packages list
#Override
protected List<ReactPackage> getPackages() {
#SuppressWarnings("UnnecessaryLocalVariable")
List<ReactPackage> packages = new PackageList(this).getPackages();
// below DefaultBrowserPackage is added to the list of packages returned
packages.add(new DefaultBrowserPackage());
return packages;
}
Now we are ready to use it inside of JS. So wherever you want to use it, you can do it like this:
import { Linking, NativeModules, Platform } from 'react-native';
// DefaultBrowserModule should be equal to the return value of the getName() method
// inside of the src/main/java/com/your-app-name/DefaultBrowserModule.java class
const { DefaultBrowserModule } = NativeModules;
export const openUrl = async (url) => {
if (Platform.OS === 'android') {
DefaultBrowserModule.openUrl(url);
} else {
await Linking.openURL(url);
}
};
// And then use it like this
await openUrl('https://my-app-link-domain.com');
Deep and universal linking happens on the operating level and it's hard to control the behavior of other app linking I think it should security breach as some apps try to override the deep link behaviors of another app.
Try to create your simple page with your custom URL https://my-domain.com which redirect to tour target URL without opening associated app.
The best possible solution for that can be using android:pathPattern in android manifest. Basically you have to provide path pattern (a sort regex) to match the valid links.
Documentation for that can be found here.
https://developer.android.com/guide/topics/manifest/data-element
I installed react-native-fs and I followed through the document. I did all the configuration but at the last, they mentioned I should make the changes in MainApplication.java . But configuration is not the same as their document.
react-native-fs ==> MainApplication.java
import com.rnfs.RNFSPackage; // <------- add package
public class MainApplication extends Application implements ReactApplication {
// ...
#Override
protected List<ReactPackage> getPackages() {
return Arrays.<ReactPackage>asList(
new MainReactPackage(), // <---- add comma
new RNFSPackage() // <---------- add package
);
}
My app ===> MainApplication.java
protected List<ReactPackage> getPackages() {
#SuppressWarnings("UnnecessaryLocalVariable")
List<ReactPackage> packages = new PackageList(this).getPackages();
// Packages that cannot be autolinked yet can be added manually here, for example:
// packages.add(new MyReactNativePackage());
return packages;
}
react-native-fs installation instructions were written long time ago when autolinking was not there(prior to React Native v0.60.0 release).
Firstly, if you are using React Native version 0.60.0+, then you do not have to perform any additional android and iOS(except the pod install for iOS) steps as described in the Readme.md of the package since autolinking will automatically handle the native configuration part.
But if you still want to manually link the library, then in your given android code in MainApplication.java file, you can add the new RNFSPackage() as shown in the code snippet below.
protected List<ReactPackage> getPackages() {
#SuppressWarnings("UnnecessaryLocalVariable")
List<ReactPackage> packages = new PackageList(this).getPackages();
// Packages that cannot be autolinked yet can be added manually here, for example:
// packages.add(new MyReactNativePackage());
packages.add(new RNFSPackage()); //<== here
return packages;
}
I am working on Spring Boot and Cloud Sleuth, migrating from Spring Boot v1.4.1.RELEASE to Spring Boot 2.2.6.RELEASE.
When I upgraded maven dependency, my code started breaking
CustomSampler.java
import org.springframework.cloud.sleuth.Sampler;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import zipkin2.Span;
#Configuration
public class CustomSampler {
#Bean
public Sampler smartSampler() {
return new Sampler() {
#Override
public boolean isSampled(Span span) {
System.out.println("custom sampler used!");
return true;
}
};
}
}
I went through this link : https://github.com/spring-cloud/spring-cloud-sleuth/wiki/Spring-Cloud-Sleuth-2.0-Migration-Guide, but things are not clear.
I used this library:
path_provider 1.5.1
It's working fine
but the pdf file not opened in full screen
Did you try flutter_full_pdf_viewer library?
import 'package:flutter/material.dart';
import 'package:flutter_full_pdf_viewer/flutter_full_pdf_viewer.dart';
class ShowPdfPage extends StatelessWidget {
String pdfPath;
#override
Widget build(BuildContext context) {
pdfPath = //your awesome path retrieved with path_provider;
return PDFViewerScaffold(path: pdfPath);
}
}
I tried the both solution new MapsPackage(this) and new MapsPackage() .But nothing works for me.
And I see the MapsPackage class, The constructor are given as below
They handling the both compatibility. with argument and without argument.
public MapsPackage(Activity activity) {
} // backwards compatibility
public MapsPackage() {
}
your information doesn't sufficient.
you can see this error when adding new module in
#Override
protected List<ReactPackage> getPackages() {
#SuppressWarnings("UnnecessaryLocalVariable")
List<ReactPackage> packages = new PackageList(this).getPackages();
packages.add(new LocationPackage());
return packages;
}
you should care about the point you import new module. This error occurs when you want to add package but import module. for example when you want to write new LocationPackage(), you write new LocationModule().