react-native-localize
react-native-localize copied to clipboard
usesAutoDateAndTime() returns true if i turned off my auto time and date setting and does not change date or time.
Bug summary
I was working with usesAutoDateAndTime() and noticed that if i turned off the setting and does not change any time or date, the function still returns me true, thou it should be false. The boolean only updates its value when we changes the time or date.
Also there's also a problem that if i turned off the auto time and date setting and changes the date, and then view logs it gives false(which is ok) but then if i manual corrects the date and turn on the setting again, it still gives me false.
I tried using Listeners, but it wont work on auto time&date setting
Library version
2.2.0
Environment info
System:
OS: macOS 11.6.1
CPU: (8) x64 Intel(R) Core(TM) i7-4980HQ CPU @ 2.80GHz
Memory: 2.24 GB / 16.00 GB
Shell: 5.8 - /bin/zsh
Binaries:
Node: 16.14.0 - /usr/local/bin/node
Yarn: Not Found
npm: 8.3.1 - /usr/local/bin/npm
Watchman: 2021.10.18.00 - /usr/local/bin/watchman
Managers:
CocoaPods: 1.11.2 - /usr/local/bin/pod
SDKs:
iOS SDK:
Platforms: DriverKit 21.0.1, iOS 15.0, macOS 12.0, tvOS 15.0, watchOS 8.0
Android SDK:
API Levels: 23, 28, 29, 30, 31
Build Tools: 28.0.3, 29.0.2, 30.0.2, 30.0.3, 31.0.0
System Images: android-19 | Google APIs ARM EABI v7a, android-19 | Google APIs Intel x86 Atom, android-30 | Google Play Intel x86 Atom
Android NDK: Not Found
IDEs:
Android Studio: 2021.1 AI-211.7628.21.2111.8139111
Xcode: 13.1/13A1030d - /usr/bin/xcodebuild
Languages:
Java: 1.8.0_292 - /usr/bin/javac
npmPackages:
@react-native-community/cli: Not Found
react: ^17.0.2 => 17.0.2
react-native: ^0.67.0 => 0.67.2
react-native-macos: Not Found
npmGlobalPackages:
*react-native*: Not Found
Steps to reproduce
- Initially turn on you auto time&date setting
- see the logs
- turn off your auto time&date setting
- see the logs
Reproducible sample code
<TouchableOpacity onPress={()=>console.log(RNLocalize.usesAutoDateAndTime())} ><Text>check setting</Text></TouchableOpacity>
@mashad6 Did you restarted the app before checking it again?
@zoontek yes i did, i tried rebuilding the app as well. its easily reproducible .
I tried it and it works as currently expected.
Go to settings, untick auto date:

The kill the app, restart it:

These methods responses are currently not updated though time. I'm waiting for wide availability of React Native JSI to make theses synchronous though threads.
@zoontek Well i did not kill the app, I used Appstate and called the function in it. so what it does is when my app goes to the settings and open app(with out killing) again, functions inside Appstate runs again . And usesAutoDateAndTime() is in it and doesnt returns the updated response
These can't be achieved for now since the response is synchronous.
can you add any listener for this setting?
Unfortunately no. Inner BroadcastReceiver
onReceive
are currently not triggered on latest Android versions, external cannot access to React context.
The only way would be to add async methods for everything (ex: usesAutoDateAndTimeAsync: Promise<boolean>
, etc.), but it's verbose and error prone. As JSI is around the corner (already present in latest react native versions, just hidden / not documented), it will be better to just wait for wide availability to make some breaking changes and switch to it entirely.
As it's not something people change every day, it's - I think - OK for now.
@zoontek Thanks man for the clarity. appreciate it.
@zoontek good morning . Congratulations for the initiative.
I'm developing an application in react where the automatic date and time information will be used to allow or disallow a user action, so I need it to reflect exactly what is set at the time of registration.
Are you thinking of working on something along these lines?