I am trying to import a file from within my project directory and I keep having the above error. I am using React-native, yarn, and Expo for this project. Here is my project directory structure:
sample
- tests
- .expo
- android
- ios
- node_modules
src
- NotificationManager.js
App.js
Here is what my App.js file looks like:
import React, {Component} from 'react'
import {View, StyleSheet, TouchableOpacity, Text} from 'react-native'
import {NotificationManager} from './src/NotificationManager'
export default class App extends Component {
constructor(props) {
super(props)
}
render() {
let {container, button} = styles
return(
<View style={container}>
<TouchableOpacity style={button}>
<Text>Send notification</Text>
</TouchableOpacity>
</View>
)
}
}
const styles = StyleSheet.create({
container: {
flex: 1,
alignItems: 'center',
justifyContent: 'center'
},
button: {
alignItems: 'center',
backgroundColor: '#DDDDDD',
padding: 10,
width: 200,
marginTop: 10
}
})
And here is what my NotificationManager.js file looks like:
import PushNotification from "react-native-push-notification"
import PushNotificationIOS from "@react-native-community/push-notification-ios"
import {Platform} from 'react-native'
class NotificationManager {
configure = () => {
PushNotification.configure({
onRegister: function(token) {
console.log("[NotificationManager] TOKEN:", token);
},
onNotification: function(notification) {
console.log("[NotificationManager] NOTIFICATION:", notification);
//process the notification
//required on iOS only
notification.finish(PushNotificationIOS.FetchResult.NoData);
}
})
}
_buildAndroidNotification = (id, title, message, data = {}, options = {}) => {
return {
id: id,
autoCancel: true,
largeIcon: options.largeIcon || "ic_launcher",
smallIcon: options.smallIcon || "ic_launcher",
bigText: message || '',
subtext: title || '',
vibrate: options.vibrate || false,
vibration: options.vibration || 300,
priority: options.priority || "high",
importance: options.importance || "high",
data: data
}
}
_buildIOSNotification = (id, title, message, data = {}, options = {}) => {
return {
alertAction: options.alertAction || "View",
category: options.category || "",
userInfo: {
id: id,
item: data
}
}
}
showNotification = (id, title, message, data = {}, options = {}) => {
PushNotification.localNotification({
...this._buildAndroidNotification(id, title, message, data, options),
...this._buildIOSNotification(id, title, message, data, options),
title: title || "",
message: message || "",
playSound: options.playSound || false,
soundName: options.soundName || 'default',
userInteraction: false
})
}
cancelAllLocalNotification = () => {
if (Platform.OS === 'ios') {
PushNotificationIOS.removeAllDeliveredNotifications()
} else {
PushNotification.cancelAllLocalNotifications()
}
unregister = () => {
PushNotification.unregister()
}
}
}
export const notificationManager = new NotificationManager()
But the error I receive with the import file is 'NotificationManager' is declared but its value is never read.ts(6133)