Related
Using native-base Modal and theming. See their theme/components/modal.ts for a reference as to what components make up a Modal and their theme.
So I'm trying to change the modal theme colors like so:
const theme = extendTheme({
...
components: {
ModalHeader: {
baseStyle: {
_dark: {
bg: "gray.700",
color: "warmGray.50",
},
},
},
ModalBody: {
baseStyle: {
_dark: {
bg: "gray.700",
color: "coolGray.300",
},
},
},
ModalFooter: {
baseStyle: {
_dark: {
bg: "gray.600",
color: "text.50",
},
},
},
ModalCloseButton: {
baseStyle: {
_dark: {
_icon: {
color: "coolGray.100",
},
},
},
},
},
});
I want to give the divider a color of gray.600 (the same as ModalFooter). However, I don't see ModalDivider as a component to color. Furthermore, the divider is no longer visible once I apply the above theme:
my modal with theme applied and missing divider. I tried also coloring ModalContent but that did not help either.
Ideally, I'd like the divider to be seen like in their docs but with my colors.
Here is their modal in dark mode:
native-base xl modal in dark mode where you can see the divider
The answer lies in borderColor for ModalHeader. Change it like so:
const theme = extendTheme({
...
components: {
ModalHeader: {
...
baseStyle: {
...
_dark: {
...
borderColor: "blue.500",
},
},
},
},
});
I'm having trouble getting my local iOS push notification to work, using React Native. I've checked similar threads but haven't been able to find the answer. This is (meant to be) a basic setup, so hopefully someone can help.
I'm trying to fire the push notification on press of TouchableOpacity objects, wrapped within a FlatList. I'm not getting any code errors, the notification just isn't firing.
I've installed both npm packages as per the documentation, and I'm using React Native v0.65.1: -
npm install --save react-native-push-notification
npm i #react-native-community/push-notification-ios --save
I've added my code below. There are other files associated to other functionality on the app, but I haven't included them here, as this is the only file which includes code for push notification support.
Where am I going wrong?
Thanks in advance...
import {Alert, FlatList, Pressable, StyleSheet, Text, TextInput, TouchableOpacity, View} from "react-native";
import React, { useEffect, useState } from "react";
import GlobalStyle from '../utils/GlobalStyle';
import CustomButton from "../utils/CustomButton";
import SQLite from "react-native-sqlite-storage";
import { useDispatch, useSelector } from "react-redux";
import { setAge, setName, increaseAge, getCities } from "../redux/actions";
import PushNotification from "react-native-push-notification";
import PushNotificationIOS from "#react-native-community/push-notification-ios";
// store sqlite open database function
const db = SQLite.openDatabase(
{ name: 'sqlite_db', location: 'default' },
() => {},
error => { console.log(error) }
);
export default function Home({ navigation, route }) {
// replace local state objects with global redux objects
const { name, age, cities } = useSelector(state => state.userReducer);
const dispatch = useDispatch();
// function calls for SQLite and api data fetch
useEffect(() => {
getData();
dispatch(getCities());
}, []);
// fetch data objects from SQLite store
const getData = () => {
try {
db.transaction((tx) => {
tx.executeSql(
'SELECT Name, Age FROM Users',
[],
(tx, results) => {
let length = results.rows.length;
if (length > 0) {
let userName = results.rows.item(0).Name;
let userAge = results.rows.item(0).Age;
dispatch(setName(userName));
dispatch(setAge(userAge));
}
}
)
})
} catch (error) {
console.log(error);
}
}
// function to update SQLite data store
const updateData = async () => {
if (name.length == 0) {
Alert.alert('WARNING!', 'Please enter your name')
} else {
try {
db.transaction((tx) => {
tx.executeSql(
'UPDATE Users SET Name=?',
[name],
() => {
Alert.alert('SUCCESS!', 'Your data has been updated')
},
error => { console.log(error) }
)
})
} catch (error) {
console.log(error)
}
}
}
// function to remove data from SQLite data store
const removeData = async () => {
try {
db.transaction((tx) => {
tx.executeSql(
"DELETE FROM Users",
[],
() => {
navigation.navigate('Login')
},
error => { console.log(error) }
)
})
} catch (error) {
console.log(error)
}
}
**object to store function, fired when touchable is clicked
bound to touchable opacity onPress**
const handleNotification = (item) => {
PushNotification.localNotification({
title: 'Push Notification',
message: 'You clicked on' + item.country
})
}
return(
<View style={styles.body}>
<Text style={[
GlobalStyle.header,
GlobalStyle.text
]}>
Welcome {name} !
</Text>
**flatlist used to display api fetch responses
push notification onPress function is bound to TouchableOpacity object**
<FlatList
data={cities}
renderItem={({item}) => (
<TouchableOpacity
onPress={() => { handleNotification(item) }}
>
<View style={styles.item}>
<Text style={styles.title}>{item.country}</Text>
<Text style={styles.subtitle}>{item.city}</Text>
</View>
</TouchableOpacity>
)}
keyExtractor={(item, index) => index.toString()}
/>
</View>
)
}
const styles = StyleSheet.create({
body: {
flex: 1,
// justifyContent: 'center',
alignItems: 'center',
},
// now obsolete, as we have replaced this with a global style
text: {
// fontWeight: 'bold',
// fontSize: 26,
margin: 10,
// fontFamily: 'TitilliumWeb-Bold'
},
navButton: {
borderRadius: 11,
paddingHorizontal: 20,
width: 180,
height: 50,
justifyContent: 'center',
alignItems: 'center'
},
openDrawerButton: {
borderRadius: 11,
paddingHorizontal: 20,
width: 180,
height: 50,
justifyContent: 'center',
alignItems: 'center',
marginTop: 10
},
thirdFont: {
fontSize: 18,
paddingTop: 20,
fontFamily: 'Roboto-Regular'
},
textInput: {
width: 250,
height: 50,
marginTop: 10,
borderRadius: 10,
backgroundColor: '#d9cbe7',
borderWidth: 2,
borderColor: '#d9c1c1',
textAlign: 'center',
fontSize: 20
},
item: {
backgroundColor: 'white',
borderWidth: 3,
borderColor: '#bfcab8',
borderRadius: 7,
margin: 7,
width: 350,
justifyContent: 'center',
alignItems: 'center',
paddingVertical: 10
},
title: {
fontSize: 20,
fontFamily: 'Ubuntu-Bold',
color: '#a03f3f'
},
subtitle: {
marginTop: 8,
fontFamily: 'Ubuntu-Regular',
fontSize: 16
}
})
import PushNotificationIOS from "#react-native-community/push-notification-ios";
export default class NotifService {
constructor(onRegister, onNotification) {
this.configure(onRegister, onNotification);
this.lastId = 0;
}
configure(onRegister, onNotification, gcm = "") {
PushNotificationIOS.configure({
// (optional) Called when Token is generated (iOS and Android)
onRegister: onRegister, //this._onRegister.bind(this),
// (required) Called when a remote or local notification is opened or received
onNotification: onNotification, //this._onNotification,
// ANDROID ONLY: GCM Sender ID (optional - not required for local notifications, but is need to receive remote push notifications)
senderID: gcm,
// IOS ONLY (optional): default: all - Permissions to register.
permissions: {
alert: true,
badge: true,
sound: true
},
// Should the initial notification be popped automatically
// default: true
popInitialNotification: true,
/**
* (optional) default: true
* - Specified if permissions (ios) and token (android and ios) will requested or not,
* - if not, you must call PushNotificationsHandler.requestPermissions() later
*/
requestPermissions: true,
});
}
localNotif(title, message, sound, color) {
this.lastId++;
PushNotificationIOS.localNotificationSchedule({
/* Android Only Properties */
id: ''+this.lastId, // (optional) Valid unique 32 bit integer specified as string. default: Autogenerated Unique ID
ticker: "My Notification Ticker", // (optional)
autoCancel: true, // (optional) default: true
largeIcon: "ic_launcher", // (optional) default: "ic_launcher"
smallIcon: "ic_notification", // (optional) default: "ic_notification" with fallback for "ic_launcher"
bigText: message, // (optional) default: "message" prop
color: color, // (optional) default: system default
vibrate: true, // (optional) default: true
vibration: 300, // vibration length in milliseconds, ignored if vibrate=false, default: 1000
tag: 'some_tag', // (optional) add tag to message
group: "group", // (optional) add group to message
ongoing: false, // (optional) set whether this is an "ongoing" notification
/* iOS only properties */
alertAction: 'view', // (optional) default: view
category: '', // (optional) default: null
userInfo: {}, // (optional) default: null (object containing additional notification data)
/* iOS and Android properties */
title: title, // (optional)
message: message, // (required)
playSound: sound, // (optional) default: true
soundName: 'default', // (optional) Sound to play when the notification is shown. Value of 'default' plays the default sound. It can be set to a custom sound such as 'android.resource://com.xyz/raw/my_sound'. It will look for the 'my_sound' audio file in 'res/raw' directory and play it. default: 'default' (default sound is played)
actions: '["Yes", "No"]', // (Android only) See the doc for notification actions to know more
});
}
checkPermission(cbk) {
return PushNotification.checkPermissions(cbk);
}
cancelNotif() {
console.log(this.lastId, "***")
PushNotification.cancelLocalNotifications({id: ''+this.lastId});
}
cancelAll() {
PushNotification.cancelAllLocalNotifications();
}
}
I am using Highcharts to create some chart but I find it's not working for changing the background of a chart's title.
For instance:
// works, the color did get to red
title: {
text: title,
style: {"color":"#ff0000"}
},
// the color did get to white but the background is not set to red.
title: {
text: title,
style: {"backgroundcolor":"#ff0000", "color":"#ffffff"}
},
What should I do to fix this?
Thanks
Referencing this question, you can do this by setting useHTML: true and using background-color.
title: {
useHTML: true,
style: {
color: '#FF00FF',
'background-color': '#000000',
fontWeight: 'bold'
}
},
https://jsfiddle.net/nicholasduffy/a32vL38z/
I use ReactNative to develop my iOS APP,to realize the QRCode scanner function,i took the react-native-camera component which provide the barcode scanner function to my project.everything goes all right,but when i had succeed in recognizing a QRCode,next time i use the model,the screen just got frozen,seems like the app goes crashed. something interesting that as the screen is frozen,and once the model cancelled from the left button of navigation,The module can work properly.
I'm not sure whether it's a inner bug of NavigatorIOS,or just the bug of react-native-camera itself.
here is the QRCode component code:
'use strict';
var React = require('react-native');
var Dimensions = require('Dimensions');
var {
StyleSheet,
View,
Text,
TouchableOpacity,
VibrationIOS,
Navigator,
} = React;
var Camera = require('react-native-camera');
var { width, height } = Dimensions.get('window');
var QRCodeScreen = React.createClass({
propTypes: {
cancelButtonVisible: React.PropTypes.bool,
cancelButtonTitle: React.PropTypes.string,
onSucess: React.PropTypes.func,
onCancel: React.PropTypes.func,
},
getDefaultProps: function() {
return {
cancelButtonVisible: false,
cancelButtonTitle: 'Cancel',
barCodeFlag: true,
};
},
_onPressCancel: function() {
var $this = this;
requestAnimationFrame(function() {
$this.props.navigator.pop();
if ($this.props.onCancel) {
$this.props.onCancel();
}
});
},
_onBarCodeRead: function(result) {
var $this = this;
if (this.props.barCodeFlag) {
this.props.barCodeFlag = false;
setTimeout(function() {
VibrationIOS.vibrate();
$this.props.navigator.pop();
$this.props.onSucess(result.data);
}, 1000);
}
},
render: function() {
var cancelButton = null;
if (this.props.cancelButtonVisible) {
cancelButton = <CancelButton onPress={this._onPressCancel} title={this.props.cancelButtonTitle} />;
}
return (
<Camera onBarCodeRead={this._onBarCodeRead} style={styles.camera}>
<View style={styles.rectangleContainer}>
<View style={styles.rectangle}/>
</View>
{cancelButton}
</Camera>
);
},
});
var CancelButton = React.createClass({
render: function() {
return (
<View style={styles.cancelButton}>
<TouchableOpacity onPress={this.props.onPress}>
<Text style={styles.cancelButtonText}>{this.props.title}</Text>
</TouchableOpacity>
</View>
);
},
});
var styles = StyleSheet.create({
camera: {
width:width,
height: height,
alignItems: 'center',
justifyContent: 'center',
},
rectangleContainer: {
flex: 1,
alignItems: 'center',
justifyContent: 'center',
backgroundColor: 'transparent',
},
rectangle: {
height: 250,
width: 250,
borderWidth: 2,
borderColor: '#00FF00',
backgroundColor: 'transparent',
},
cancelButton: {
flexDirection: 'row',
justifyContent: 'center',
backgroundColor: 'white',
borderRadius: 3,
padding: 15,
width: 100,
marginBottom: 10,
},
cancelButtonText: {
fontSize: 17,
fontWeight: '500',
color: '#0097CE',
},
});
module.exports = QRCodeScreen;
And In another Component I push this qrCode to the new sence:
'use strict';
var React = require('react-native');
var {
AppRegistry,
StyleSheet,
Text,
View,
TouchableOpacity,
NavigatorIOS,
AlertIOS,
Navigator,
} = React;
var QRCodeScreen = require('./QRCodeScreen');
var cameraApp = React.createClass({
render: function() {
return (
<NavigatorIOS
style={styles.container}
initialRoute={{
title: 'Index',
backButtonTitle: 'Back',
component: Index,
}}
/>
);
}
});
var Index = React.createClass({
render: function() {
return (
<View style={styles.contentContainer}>
<TouchableOpacity onPress={this._onPressQRCode}>
<Text>Read QRCode</Text>
</TouchableOpacity>
</View>
);
},
_onPressQRCode: function() {
this.props.navigator.push({
component: QRCodeScreen,
title: 'QRCode',
passProps: {
onSucess: this._onSucess,
},
});
},
// onPressCancel:function(){
//
// this.props.navigator.getContext(this).pop();
//
// },
_onSucess: function(result) {
AlertIOS.alert('Code Context', result, [{text: 'Cancel', onPress: ()=>console.log(result)}]);
// console.log(result);
},
});
var styles = StyleSheet.create({
container: {
flex: 1,
backgroundColor: '#F5FCFF',
},
contentContainer: {
flex: 1,
alignItems: 'center',
justifyContent: 'center',
}
});
AppRegistry.registerComponent('Example', () => cameraApp);
Any answer will be helpful!
I think it's a inner bug of NavigatorIOS, or maybe just sth else wrong.
Blew is my code, it is ok.
'use strict';
const React = require('react-native');
const {
AppRegistry,
StyleSheet,
Text,
View,
TouchableOpacity,
Navigator,
} = React;
var QRCodeScreen = require('./QRCodeScreen');
const CameraApp = () => {
const renderScene = (router, navigator) => {
switch (router.name) {
case 'Index':
return <Index navigator={navigator}/>;
case 'QRCodeScreen':
return <QRCodeScreen
onSucess={router.onSucess}
cancelButtonVisible={router.cancelButtonVisibl}
navigator={navigator}
/>;
}
}
return (
<Navigator
style={styles.container}
initialRoute={{
name: 'Index',
}}
renderScene={renderScene}
/>
);
};
const Index = ({navigator}) => {
const onPressQRCode = () => {
navigator.push({
name: 'QRCodeScreen',
title: 'QRCode',
onSucess: onSucess,
cancelButtonVisible: true,
});
};
const onSucess = (result) => {
console.log(result);
};
return (
<View style={styles.contentContainer}>
<TouchableOpacity onPress={onPressQRCode}>
<Text>Read QRCode</Text>
</TouchableOpacity>
</View>
);
};
module.exports = CameraApp;
const styles = StyleSheet.create({
container: {
flex: 1,
backgroundColor: '#F5FCFF',
},
contentContainer: {
flex: 1,
alignItems: 'center',
justifyContent: 'center',
}
});
you can try Library react native qrcode
https://github.com/moaazsidat/react-native-qrcode-scanner. on me ,
its run. you can try . in ios and android.
I am using qtip plug in to show balloon conversation on my page. i can load the balloon, but i am not seeing any option to close it automatically after some seconds.
This is how i am using qtip -
$('#ShowBalloon')
.click(function()
{
if($("#content a").data("qtip")) $("#content a").qtip("destroy");
$("#content a").html("") // Set the links HTML to the current opposite corner
.qtip({
content: { text: 'You have 1 new message.' },
position: {
corner: {
tooltip: 'bottomRight',
target: 'topRight'
}
},
show: {
when: false,
ready: true,
effect: { type: 'fade' },
length: 2000
},
hide: { when: 'inactive', delay: 1000 },
style: {
border: {
width: 1,
radius: 7,
color : "#00AFF0"
},
title: { 'color': 'red', 'overflow': 'hidden' },
width: 300,
color:'White',
background: '#00AFF0',
padding: 10,
textAlign: 'center',
tip: true,
}
});
});