I'm making an app which wants the user to keep the app open and not using other apps (to help them focuses on works), but allows them to turn the phone screen off. I used AppState API to detect if the app running in the background but it also triggered when the screen turned off.
So I need a way to know if the screen is on or off. I tried googling around but I couldn't find any solution.
Related
A React Native-specific version of this question was asked, but not answered React-Native: How can I disable all push notifications while my app is active?
Essentially, is there a way to remove interruptions while my app is in the foreground? Ideally there would be a "focus" state I put the app into that minimizes disruptions, but I can't find an API like that.
Concretely, part of my app involves meditation states. Getting popups during one of those is distracting, so I'd like to disable banners and alerts while one of those sessions is running.
Happy to hear it's not possible, just haven't actually found that answer yet.
No, you don't have an API or control over other apps notifications. But surely you can control your app notifications. You can handle those notifications without prompting. Let me know if this is helpful.
I'm using expo screen orientation package to handle my apps screen orientations but it does not take into consideration if the user have turned auto rotate on/off in the device settings.
I tried the react-native-orientation-locker package as well but I can't get that to work at all on my app for some reason.
Is there any way of telling what the user preference is regarding the auto rotate? I can't find any examples of it anywhere. Surely others needed this info as well.
Im trying to develop an app in react native that can detect if the screen of the user is physically broken. It's for an insurance company that wants to check if someone's phone isn't already broken when they insure it.
Obviously I can just ask the user to take a picture of the phone pointing at a mirror and validate it my self.
But instead, i've been wondering if even such technology exists or maybe there is work around for the matter. Probably painting the entire screen to detect pixel by pixel if any is broken but I don't know how to do that or what to use.
If anyone knows if a way exists I would be very grateful.
TL;DR- No.
Not only in react native, even in native android or ios api there is no such thing to check screen damage.
As far as your app is concerned, user involvement is necessary to detect screen or touch damage.
Just display different colors on screen and ask user to check for any discoloration or “dead” pixels.
And for touch, ask user to tap different parts of screen or drag finger accross and check for touch misses or bad areas.
There are some good touch testing apps available on the play store, give them a shot.
Firstly, apologies for the slightly open ended questions but I can't find the info I'm looking for in other questions.
I'm trying to understand the lifecycle of a RN app on both iOS and Android. I understand the app bootstraps when you first start it and stays running while the phone is alive, but what happens when the user switches to a different app and comes back, or their screen times out then they switch it back on? It would be really annoying if the app restarted just because they briefly switched to check their email.
My specific use case (not particularly important to this generic question but included for context) is that I'm trying to build a game with socket.io connections and I'm wondering if I can hook into events to see if the app has been in the background or if I even need to. I have found a way of forcing a restart which may be necessary at some points, but I'd rather just try to reconnect things that have disconnected if I can find out when that happens.
Any push in the right direction would be appreciated.
The app doesn't restart when it goes in the background as you describe. The app keeps its state and the user sees the last screen they visited.
You should have a look at react native's AppState
https://facebook.github.io/react-native/docs/appstate
Using AppState you can addEventListeners that capture the change of the app's state like when going to background.
Of course there are also some problems here...
You can't capture the "kill "event. You can only detect if the app is sent to the background but unfortunately you can't detect when the user chooses to "kill" the app
You can't run any code while your app is in the background. This might be serious in your case but you should evaluate it. For example if you have a timer and you sent the app to the background then the timer stops.
I wonder if it's possible delete the transition that leads to my WP8.1 universal app when it's launched. So, when my app is launched, I want it to just show the SplashScreen without any animation. I've already read this and this questions, but since I'm not navigating between pages within my app, I can't just set "ContentTransitions" of my frame to null.
Does anybody have any information on this? Or is it just not possible, since these "launching" transitions are managed by the OS?
Disable the animations on the Frame, hook up the Frame`s navigated event and enable them back after first navigation. I have a post about this here.
The initial splash screen is displayed by the OS until you call Window.Current.Activate(). You cannot disable/modify this transition, and you should also not try to do so as your app will lose parity with the rest of OS ecosystem.