GithubHelp home page GithubHelp logo

ravnhq / react-native-midnight Goto Github PK

View Code? Open in Web Editor NEW
34.0 3.0 6.0 1.22 MB

Subscribe to day change

License: MIT License

JavaScript 12.52% Kotlin 12.51% Java 30.91% TypeScript 15.51% Swift 4.91% C 0.51% Objective-C 17.27% Ruby 5.87%
midnight react-native day-changed calendardaychanged time-changed date-changed timezone-changed

react-native-midnight's Introduction

React Native Midnight

Simple react native package for listening to date changes

CI status codecov semantic-release NPM version NPM downloads

Installation

# with npm
npm install --save react-native-midnight

# with yarn
yarn add react-native-midnight

API

Midnight.addListener

The addListener function connects a function to a day change notification event.

This function then returns the reference to the listener. You can remove the listener by calling the remove method on it.

import Midnight from 'react-native-midnight'

const App = () => {
  React.useEffect(() => {
    const listener = Midnight.addListener(() => {
      Alert.alert('The day has changed')
    })
    return () => listener.remove()
  }, [])

  return <Text>App</Text>
}

useOnDayChange

Convenience hook that calls the passed function when the day changes

useOnDayChange((callback: () => void))

Note: Because useOnDayChange doesn't watch for dependency changes, the listener will be removed and re-added every time this hook is called. Creating your own effect inline with Midnight.addListener might be preferred if this is an issue.

Contributing

See the contributing guide to learn how to contribute to the repository and the development workflow.

License

MIT

react-native-midnight's People

Contributors

donovanhiland avatar manasv avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

react-native-midnight's Issues

new react version kotlin issue

The Android Gradle plugin supports only Kotlin Gradle plugin version 1.5.20 and higher.
The following dependencies do not satisfy the required version:
project ':react-native-midnight' -> org.jetbrains.kotlin:kotlin-gradle-plugin:1.3.50

Crash in broadcast receiver

Hi,

I was inspecting adb logs and found this crash, RN complains about Tried to access a JS module before the React instance was fully set up. Calls to ReactContext#getJSModule should only happen once initialize() has been called on your native module..

05-15 08:20:48.725  4058  4058 E AndroidRuntime: FATAL EXCEPTION: main
05-15 08:20:48.725  4058  4058 E AndroidRuntime: Process: com.screenmanager, PID: 4058
05-15 08:20:48.725  4058  4058 E AndroidRuntime: java.lang.RuntimeException: Error receiving broadcast Intent { act=android.intent.action.TIME_SET flg=0x25200010 } in com.reactnativemidnight.MidnightModule$midnightBroadcastReceiver$1@23916ad
05-15 08:20:48.725  4058  4058 E AndroidRuntime: 	at android.app.LoadedApk$ReceiverDispatcher$Args.lambda$getRunnable$0(LoadedApk.java:1401)
05-15 08:20:48.725  4058  4058 E AndroidRuntime: 	at android.app.-$$Lambda$LoadedApk$ReceiverDispatcher$Args$_BumDX2UKsnxLVrE6UJsJZkotuA.run(Unknown Source:2)
05-15 08:20:48.725  4058  4058 E AndroidRuntime: 	at android.os.Handler.handleCallback(Handler.java:873)
05-15 08:20:48.725  4058  4058 E AndroidRuntime: 	at android.os.Handler.dispatchMessage(Handler.java:99)
05-15 08:20:48.725  4058  4058 E AndroidRuntime: 	at android.os.Looper.loop(Looper.java:193)
05-15 08:20:48.725  4058  4058 E AndroidRuntime: 	at android.app.ActivityThread.main(ActivityThread.java:6680)
05-15 08:20:48.725  4058  4058 E AndroidRuntime: 	at java.lang.reflect.Method.invoke(Native Method)
05-15 08:20:48.725  4058  4058 E AndroidRuntime: 	at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
05-15 08:20:48.725  4058  4058 E AndroidRuntime: 	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)
05-15 08:20:48.725  4058  4058 E AndroidRuntime: Caused by: java.lang.RuntimeException: Tried to access a JS module before the React instance was fully set up. Calls to ReactContext#getJSModule should only happen once initialize() has been called on your native module.
05-15 08:20:48.725  4058  4058 E AndroidRuntime: 	at com.facebook.react.bridge.ReactContext.getJSModule(ReactContext.java:127)
05-15 08:20:48.725  4058  4058 E AndroidRuntime: 	at com.reactnativemidnight.MidnightModule.sendDayChangedEvent(MidnightModule.kt:28)
05-15 08:20:48.725  4058  4058 E AndroidRuntime: 	at com.reactnativemidnight.MidnightModule.access$sendDayChangedEvent(MidnightModule.kt:15)
05-15 08:20:48.725  4058  4058 E AndroidRuntime: 	at com.reactnativemidnight.MidnightModule$midnightBroadcastReceiver$1.onReceive(MidnightModule.kt:37)
05-15 08:20:48.725  4058  4058 E AndroidRuntime: 	at android.app.LoadedApk$ReceiverDispatcher$Args.lambda$getRunnable$0(LoadedApk.java:1391)
05-15 08:20:48.725  4058  4058 E AndroidRuntime: 	... 8 more

Any idea what is wrong?

Versions:

"react-native": "0.62.2",
"react-native-midnight": "^1.0.2",

The automated release is failing 🚨

🚨 The automated release from the master branch failed. 🚨

I recommend you give this issue a high priority, so other packages depending on you could benefit from your bug fixes and new features.

You can find below the list of errors reported by semantic-release. Each one of them has to be resolved in order to automatically publish your package. I’m sure you can resolve this πŸ’ͺ.

Errors are usually caused by a misconfiguration or an authentication problem. With each error reported below you will find explanation and guidance to help you to resolve it.

Once all the errors are resolved, semantic-release will release your package the next time you push a commit to the master branch. You can also manually restart the failed CI job that runs semantic-release.

If you are not sure how to resolve this, here is some links that can help you:

If those don’t help, or if this issue is reporting something you think isn’t right, you can always ask the humans behind semantic-release.


Invalid npm token.

The npm token configured in the NPM_TOKEN environment variable must be a valid token allowing to publish to the registry https://registry.npmjs.org/.

If you are using Two Factor Authentication for your account, set its level to "Authorization only" in your account settings. semantic-release cannot publish with the default "
Authorization and writes" level.

Please make sure to set the NPM_TOKEN environment variable in your CI with the exact value of the npm token.


Good luck with your project ✨

Your semantic-release bot πŸ“¦πŸš€

Custom midnight hour

It can be good that we can change the midnight time. How to achieve this. Like i want to end midnight at 02:00 etc.

iOS requiresMainQueueSetup warning

When I run it on iOS, I get a warning about requiresMainQueueSetup not being set.

Once I did, I applied the following patch in patch-package. However, I am not familiar with swift.

diff --git a/node_modules/react-native-midnight/ios/Midnight.swift b/node_modules/react-native-midnight/ios/Midnight.swift
index 82ba4cf..746f19b 100644
--- a/node_modules/react-native-midnight/ios/Midnight.swift
+++ b/node_modules/react-native-midnight/ios/Midnight.swift
@@ -4,6 +4,10 @@ import Foundation
 
 @objc(Midnight)
 class Midnight: RCTEventEmitter {
+    override static func requiresMainQueueSetup() -> Bool {
+        return true
+    }
+
     // MARK: RN Exposed Methods
     @objc func triggerDayChangedEvent() {
         NotificationCenter

RN: 0.64.2

The automated release is failing 🚨

🚨 The automated release from the master branch failed. 🚨

I recommend you give this issue a high priority, so other packages depending on you could benefit from your bug fixes and new features.

You can find below the list of errors reported by semantic-release. Each one of them has to be resolved in order to automatically publish your package. I’m sure you can resolve this πŸ’ͺ.

Errors are usually caused by a misconfiguration or an authentication problem. With each error reported below you will find explanation and guidance to help you to resolve it.

Once all the errors are resolved, semantic-release will release your package the next time you push a commit to the master branch. You can also manually restart the failed CI job that runs semantic-release.

If you are not sure how to resolve this, here is some links that can help you:

If those don’t help, or if this issue is reporting something you think isn’t right, you can always ask the humans behind semantic-release.


Cannot push to the Git repository.

semantic-release cannot push the version tag to the branch master on the remote Git repository with URL https://[secure]@www.github.com/ravnhq/react-native-midnight.

This can be caused by:


Good luck with your project ✨

Your semantic-release bot πŸ“¦πŸš€

Not working when app is cleared from recent task list

Hi this is great library. its working when Application running in
background( here it means App is visible to user Or app is in recent task list)

But it is not working when user clear it from recent task list,
Tested in release version of react native app

Thanks.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.