Stop users from swiping down on Lockscreen/Notification Center in a react-native app

With the release of iOS 11, there was a change in how the system prioritizes gestures on screen edges versus user-defined gestures. Previously, when the status bar was hidden, iOS would give priority to custom gestures on screen edges.

Now, in order to achieve the same behavior, developers need to override the

preferredScreenEdgesDeferringSystemGestures
method as detailed in this article: .

Is there a way to implement this in react-native? Has this been addressed in a recent version or is it not included in the source code?

Answer №1

To achieve this, you can switch the UIViewController currently being used to one that implements

preferredScreenEdgesDeferringSystemGestures
according to your preferences.

Firstly, start by creating a new class called MainViewController, which will return the desired value:

//
//  MainViewController.h
//

#import <UIKit/UIKit.h>

NS_ASSUME_NONNULL_BEGIN

@interface MainViewController : UIViewController

@end

NS_ASSUME_NONNULL_END

Then in MainViewController.m:

//
//  MainViewController.m
//

#import "MainViewController.h"

@interface MainViewController ()

@end

@implementation MainViewController

- (UIRectEdge)preferredScreenEdgesDeferringSystemGestures
{
  return UIRectEdgeBottom;
}

@end

Lastly, replace the generic view controller with the specialized one we just created:


 #import "AppDelegate.h"
+#import "MainViewController.h"

 #import <React/RCTBundleURLProvider.h>
 #import <React/RCTRootView.h>

===== SNIP =====

   rootView.backgroundColor = [[UIColor alloc] initWithRed:1.0 green:1.0 blue:1.0 alpha:1.0];

   self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
-  UIViewController *rootViewController = [UIViewController new];
+  UIViewController *rootViewController = [MainViewController new];
   rootViewController.view = rootView;
   self.window.rootViewController = rootViewController;
   [self.window makeKeyAndVisible];

Answer №2

By utilizing method swizzling in a Swift extension on UIViewController, I successfully resolved the issue:

extension UIViewController {
fileprivate static func implementSystemGesturesReduction() {
      guard let aClass = NSClassFromString("RNNNavigationController") ?? NSClassFromString("RNNStackController"), // aClass?.alloc() as? UINavigationController
      let originalMethod = class_getInstanceMethod(aClass, #selector(getter: UIViewController.preferredScreenEdgesDeferringSystemGestures)),
      let swizzledMethod = class_getInstanceMethod(aClass, #selector(getter: preferredScreenEdgesDeferringSystemGesturesSwizzled)) else { return }
      method_exchangeImplementations(originalMethod, swizzledMethod)
  }

  @objc public var preferredScreenEdgesDeferringSystemGesturesSwizzled: UIRectEdge {
       return .all
  }
}

To implement this logic, simply call the static method in your AppDelegate:

 UIViewController.implementSystemGesturesReduction()

Similarly, you can utilize swizzle to set prefersHomeIndicatorAutoHidden and achieve desired functionality until a more permanent solution is provided.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Steer clear of directly accessing views in AngularJS using angular-ui-router

In my AngularJS App setup, I have the following configuration: angular .module('MyApp') .config(['$stateProvider', '$urlRouterProvider', '$locationProvider', function($stateProvider, $urlRouterProvi ...

GameCenter's endTurnWithNextParticipants feature seems to be stuck and not moving forward

I am facing an issue in the sandbox environment where I cannot progress a turn-based match to the next player. Initial Setup: Player A and Player B are on Device A and Device B respectively. Both players are logged into the sandbox. Both players can vie ...

Changing the background color of a button

In the HEADER section, there are 4 buttons (B1, B2, B3, B4), each leading to a different page in the same tab. The background color of the buttons is set to WHITE. When a specific button is clicked, the entire page reloads and redirects to the correspond ...

Discover the best correlation among multiple arrays

I am currently developing a chat script that allows users to specify their interests. Upon connecting to the server, the client sends a JSON payload over WebSocket containing information such as ID, hash, auto message, and interests. {"id": int, "hash": m ...

Choose all items on each page with Material-UI's table pagination

Can items be selected solely on the current page or per page within the Table? Check out this demo for reference. ...

Combining a name using JavaScript even if certain parts are not available

How can I efficiently combine name elements without any extra white space in Vue.js? let FirstName = "John" let MI = "G" let LastName = "Jones" let Suffix = "Jr." I want to create let fullName = "John G Jones Jr." However, in cases like this: let First ...

Could you please provide me with the option to send a list of the

Is there a way to send output via email instead of displaying it in the following div: <div id="fullCalendar" ></div> After spending a whole night searching online, I couldn't find a solution. As I'm not very familiar with jQuery pr ...

Discover the most frequently repeated elements in a JavaScript array

I'm working with an array that contains multiple names such as: [mike, bob, john, john, rick, bob] Could anyone advise on the most efficient method to determine which name appears the most frequently? ...

Leveraging promises to make Ajax calls without repeating code

Would it be possible to create an ajax function without duplicating it? Passing different parameters, which are locations to various files. Then utilizing the promise to combine them into a single object, possibly incorporating the spread operator. Is th ...

What is the proper syntax for using .focus() with the nextElementSibling method in typing?

As I strive to programmatically shift focus in my form using nextElementSibling, I encounter a challenge with typing variables/constants due to working with Typescript... I have managed to achieve success without typing by implementing the following: myF ...

JavaScript for URL encoding

Hey there, I've been using the function below to encode my data and send it through the GET method. I'm utilizing AJAX for sending and PHP for receiving. function urlencode(a){ a=encodeURIComponent(a); a=a.replace(/\\/g,&apos ...

Setting the alignment of text labels with multiple lines

I need help with aligning the text on a label to always start from the top left corner, regardless of the height and number of lines in the label. Currently, I am using the following property: [question1Label setContentMode: UIViewContentModeTopLeft]; H ...

Issue with parameter functionality not working as expected

This code snippet is not functioning as expected. I am trying to extract and print the values from the URL parameter file:///C:/Users/laddi/Desktop/new%201.html?t=vindu&b=thind function GetURLParameterValue(param) { var pageURL = window. ...

In iOS 10, the deviceready event will only trigger after a delay of 30 seconds

When running my Ionic app on my iOS device using the command ionic run ios --device -lcs, I am experiencing issues with deviceready not firing or being delayed. To troubleshoot, I have tried removing all plugins using ionic plugin rm ..., clearing the con ...

Begin by setting the href attribute for the anchor tag followed by defining the

Can the href be executed before the onclick event in an anchor tag? frameDoc.body.innerHTML+='<div style="margin-left:10;"><li class="highlight"><a href="'+tmp1+'" onclick="highlightSearch(this);">'+searched_headings ...

Finding the average JSON value using d3.js

Here is the structure of a JSON file I am working with: [ {"id":1,"sex":"Female","programming":5, "project":7}, {"id":2,"sex":"Male","programming":8, "project":4}, {"id":3,"sex":"Female","programming":5, "project":6}, {"id":4,"sex":"Male","programm ...

Finding the date of a month prior based on a fixed initial date - here's how!

I have a specific requirement to display a subscription date range on a webpage in the following format: 31 May 2023 — 30 June 2023 When a user subscribes, the backend sends a fixed subscription start date that remains constant. For example, if a user ...

Stable and persistent popup window that remains at the forefront in a Chrome extension

Currently developing a Google Chrome extension and seeking assistance in creating a popup window that remains fixed in one corner while staying on top of all other windows. Here is a reference image for clarification: https://i.stack.imgur.com/IPw7N.jpg ...

Closing WebSocket connection after sending data

I came across an interesting blog post titled Experimenting with Node.js and decided to try setting it up on my own using the author's provided gist. Unfortunately, I encountered some issues. After further investigation, I discovered that even though ...

Utilize client-side script in nodejs to share module functionalities

I created a function within the user controller module to verify if a user is logged in on the site: exports.isLoggedIn = function(req, res, next) { if (req.user) { return true; } else { return false; } }; I'm unsure of h ...