Fork me on GitHub
#cljsrn
<
2022-01-29
>
FlorianK15:01:09

Hey all, I've got a very basic android app running locally using krell. It's basically a list of items that can be edited succesfully. I now want to send a very basic local push notification using [react-native-push-notification](https://github.com/zo0r/react-native-push-notification#usage). My experience level with react native, javascript and mobile development are low (I mainly do backend development in Python). I struggle a bit with getting it to work and with effectively investigating what's blocking me, so here are a few questions. Hopefully someone can help set me back on the right path 🙂 1. I'm trying to get my import working correctly. According to the documentation linked above, I should import PushNotification from react-native-push-notification. My require looks like this:

(:require [reagent.core :as r]
            [reagent.react-native :as rn]
            [tick.core :as t]
            ["react-native-push-notification" :as rnpn :refer [PushNotification]])
When I run (in-ns 'reminder.core) in the REPL and try to evaluate PushNotification I get a nil as response. However, when I try to see what rnpn (the import :as) is, it does seem to point to something:
reminder.core=> rnpn
#js {:handler #object[NotificationsComponent [object Object]], :onRegister false, :onRegistrationError false, :onNotification false, :onAction false, :onRemoteFetch false, :isLoaded false, :isPopInitialNotification false, :isPermissionsRequestPending false, :permissions #js {:alert true, :badge true, :sound true}, :callNative #object[Function], :configure #object[Function], :unregister #object[Function], :localNotification #object[Function], :localNotificationSchedule #object[Function], :_onRegister #object[Function], :_onRegistrationError #object[Function], :_onRemoteFetch #object[Function], :_onAction #object[Function], :_transformNotificationObject #object[Function], :_onNotification #object[Function], :_onPermissionResult #object[Function], :_requestPermissions #object[Function], :requestPermissions #object[Function], :subscribeToTopic #object[Function], :unsubscribeFromTopic #object[Function], :presentLocalNotification #object[Function], :scheduleLocalNotification #object[Function], :cancelLocalNotifications #object[Function], :cancelLocalNotification #object[Function], :clearLocalNotification #object[Function], :cancelAllLocalNotifications #object[Function], :setApplicationIconBadgeNumber #object[Function], :getApplicationIconBadgeNumber #object[Function], :popInitialNotification #object[Function], :checkPermissions #object[Function], :abandonPermissions #object[Function], :clearAllNotifications #object[Function], :removeAllDeliveredNotifications #object[Function], :getDeliveredNotifications #object[Function], :getScheduledLocalNotifications #object[Function], :removeDeliveredNotifications #object[Function], :invokeApp #object[Function], :getChannels #object[Function], :channelExists #object[Function], :createChannel #object[Function], :channelBlocked #object[Function], :deleteChannel #object[Function], :setNotificationCategories #object[Function], :Importance #js {:DEFAULT 3, :HIGH 4, :LOW 2, :MIN 1, :NONE 0, :UNSPECIFIED -1000}}
To my inexperienced javascript eyes this indeed does look like a Notification object that is exported from the react-native-push-notification source index.js. I couldn't find a link to that, but I don't think it's that important to my question. Does someone know what is incorrect in my import statement and why I can't seem to get the PushNotification object? 2. In the REPL I try to experiment a bit with calling functions from rnpn from the repl. For example. (rnpn/configure #js {"onNotification" console/log}) leads to the following output:
Could not evaluate form: (function (){try{return cljs.core.pr_str.call(null,(function (){var ret__6855__auto__ = reminder.core.node$module$react_native_push_notification.configure(({"onNotification": console.log}));
(cljs.core._STAR_3 = cljs.core._STAR_2);

(cljs.core._STAR_2 = cljs.core._STAR_1);

(cljs.core._STAR_1 = ret__6855__auto__);

return ret__6855__auto__;
})());
}catch (e4693){var e__6856__auto__ = e4693;
(cljs.core._STAR_e = e__6856__auto__);

throw e__6856__auto__;
}})() [TypeError: null is not an object (evaluating 'RNPushNotification.getInitialNotification')]
Apart from the 'RNPushNotification.getInitialNotification', which is probably related to the contents of react-native-push-notification, is my call ok clojurescriptwise? In other words: I'm now going to investigate more of the functional aspects of the module, is that likely to solve my problem, or is there something inherently wrong with the function call? Thanks in advance for any pointers! It's hard to formulate a clear question when you're diving into a completely new topic :)

dima09:01:35

rnpn is the same as PushNotification in javascript example when they import it with import PushNotification from "react-native-push-notification"; So you could call configure for example like (.configure rnpn #js {:onNotification (fn []) :onRegister (fn [])})

FlorianK08:02:33

Ah, cool, thanks! :)

dnolen19:01:44

@clojurians-slack992 rnpn is the thing, I think what is wrong is the refer you probably don't need that?

FlorianK09:01:36

Ah thanks, so getting the rnpn to work should be my main focus. Cool, I think I'll be able to figure something out, at least I'm on the right track then :)