I am using search icon button from antd See Example 2 From the Website, or you can see the code from here as well:
import React from 'react';
import ReactDOM from 'react-dom';
import 'antd/dist/antd.css';
import { Button, Tooltip } from 'antd';
import { SearchOutlined } from '#ant-design/icons';
ReactDOM.render(
<>
<Tooltip title="search">
<Button type="primary" shape="circle" icon={<SearchOutlined />} />
</Tooltip>
</>,
document.getElementById('container'),
);
I have used the exact same code, but in my output, the search icon is not in the center, rather it is on the left.
Why is this so?
I am facing the same issue as you. I resolved this by overwrite the default CSS. You can add the following in your App.css
.anticon svg {
display: block;
}
Let me know if this helps.
Related
I am developing a Twilio Flex plugin using Flex Ui version 2 (beta.1 and beta.2).
I wanted to add multiple tabs to TaskCanvasTabs and tried to write the following code.
import React from 'react';
import { Tab } from '#twilio/flex-ui';
import { FlexPlugin } from '#twilio/flex-plugin';
import SmsPanel from './components/SmsPanel/SmsPanel';
import IncomingVideo from './components/IncomingVideo/IncomingVideo';
const PLUGIN_NAME = 'SendSmsV2Plugin';
export default class SendSmsV2Plugin extends FlexPlugin {
constructor() {
super(PLUGIN_NAME);
}
/**
* This code is run when your plugin is being started
* Use this to modify any UI components or attach to the actions framework
*
* #param flex { typeof import('#twilio/flex-ui') }
*/
async init(flex, manager) {
const options = {
align: 'end',
};
flex.TaskCanvasTabs.Content.add(
<Tab label='SMS' key='sms-panel-tab-key'>
<SmsPanel key='sms-panel-component' />
</Tab>,
options,
);
flex.TaskCanvasTabs.Content.add(
<Tab label='Video' key='video-panel-tab-key'>
<IncomingVideo key='incoming-video-component' />
</Tab>,
options,
);
}
}
When executed, the first Tab (SMS) added will be duplicated as shown below. Thereafter, each time I select the first Tab, Call tab, etc., the first Tab added will be increased.
Can someone please tell me if the specification does not allow adding multiple tabs to TaskCanvasTabs or how to solve this problem?
I also tried with Flex Ui version 2 (beta.3) but the behavior is the same.
It seems that this issue only happens when you try to add multiple tabs on TaskCanvasTabs
To resolve this issue you could add a Tab Group which contains Tabs
flex.TaskCanvasTabs.Content.add(
<Flex.Tabs key="custom-tabs-group">
<Flex.Tab key="conversation-note-tab" label="Conversation Notes">
<ConversationNote key="conversation-note" />
</Flex.Tab>
<Flex.Tab key="label-to-conversation" label="Conversation Label">
<AttachLabelToConversation key="add-label-to-conversation" />
</Flex.Tab>
</Flex.Tabs>,
{}
);
Use this css to adjust the tab group text
/* Added CSS for merged TaskCanvasTabs into Tabs group start */
.Twilio-TaskCanvas .Twilio-TaskCanvas-default .Twilio-TaskCanvasTabs div[data-test="customer-tab-header"]:has(> div > button) button {
width: 100%;
height: 100%;
}
.Twilio-TaskCanvas .Twilio-TaskCanvas-default .Twilio-TaskCanvasTabs div[data-test="customer-tab-header"]:has(> div > button) button:hover {
background-color: unset;
}
.Twilio-TaskCanvas .Twilio-TaskCanvas-default .Twilio-TaskCanvasTabs div[data-test="customer-tab-header"]:has(> div > button) button div svg {
display: none;
}
.Twilio-TaskCanvas .Twilio-TaskCanvas-default .Twilio-TaskCanvasTabs div[data-test="customer-tab-header"]:has(> div > button) button div:after {
content: "Conversation Actions";
font-size: 14px;
font-weight: 600;
color: rgb(96, 107, 133);
padding-bottom: 6px;
}
/* Added CSS for merged TaskCanvasTabs into Tabs group end */
I heard the best solution.
TabPros is using the optional uniqueName prop instead of the key for identifying the selected tab.
So, I changed my code below. It was fixed.
flex.TaskCanvasTabs.Content.add(
<Tab label='SMS' key='sms-panel-tab-key' uniqueName='sms-panel-tab'>
<SmsPanel key='sms-panel-component' />
</Tab>,
options,
);
flex.TaskCanvasTabs.Content.add(
<Tab label='Video' key='video-panel-tab-key' uniqueName='video-panel-tab'>
<IncomingVideo key='incoming-video-component' />
</Tab>,
options,
);
The link referenced is below.
https://github.com/twilio/flex-plugin-builder/issues/327
I have seen various similar posts with the problem of the iOS status bar overlaying onto the header of apps.
I haven’t yet seen another post which has the same problem as mine.
I am trying to use a shared header component for certain pages and when I use this, I get the overlaying problem.
I have simplified the code and recreated my problem using the ionic tabs starter template:
This page is using a shared header component:
<ion-header>
<shared-header title="Home - shared header"></shared-header>
</ion-header>
shared-header.component.html
<ion-navbar>
<ion-title>{{title}}</ion-title>
</ion-navbar>
shared-header.component.ts
import { Component, Input } from '#angular/core';
#Component({
selector: 'shared-header',
templateUrl: 'shared-header.component.html'
})
export class SharedHeaderComponent {
#Input('title') title: string;
constructor() { }
}
This page is not using the shared header component:
<ion-header>
<ion-navbar>
<ion-title>
About
</ion-title>
</ion-navbar>
</ion-header>
Why would this be happening? Is it because of the extra <shared-header></shared-header> tags? If so, what can be done to solve this?
The problem is caused by having the component tag inside the header tag, for some reason this causes the header to render incorrectly. The solution I used was to use an attribute in the header instead of the component tags.
Inside the component wrap the selector in square brackets to define it be able to use it as an attribute
shared-header.component.ts
import { Component, Input } from '#angular/core';
#Component({
selector: '[shared-header]',
templateUrl: 'shared-header.component.html'
})
export class SharedHeaderComponent {
#Input('title') title: string;
constructor() { }
}
then in the header you can inject the component as an attribute like this
<ion-header shared-header title="Home - shared header">
</ion-header>
If you want to have access to your component via tags as well as an attribute, you can define multiple selectors
#Component({
selector:'[shared-header], shared-header',
templateUrl: 'shared-header.component.html'
})
You can try these below steps
1) Using statusbar cordova plugin, you can set
if (this.statusBar) {
this.statusBar.styleDefault();
this.statusBar.overlaysWebView(false);
}
2) In index.html, meta tag include 'viewport-fit=cover'
<meta name="viewport" content="viewport-fit=cover, width=device-width, initial-scale=1.0, maximum-scale=1.0, target-densityDpi=device-dpi"/>
Can you also try adding padding-top to the header classes
header {
/* ... */
/* Status bar height on iOS 10 */
padding-top: 0px;
/* Status bar height on iOS 11.0 */
padding-top: constant(safe-area-inset-top);
/* Status bar height on iOS 11+ */
padding-top: env(safe-area-inset-top);
}
I am trying to create a simple and standard chat window just like WhatsApp, Telegram, etc. Where when the inputbox on the bottom of the screen got focus, the keyboard appear and the inputbox goes right about the keyboard like this...
This is my code...
import React from 'react'
import {Actions} from 'react-native-router-flux'
import {ScrollView, View, TextInput, Text} from 'react-native'
import style from './style'
class Chat extends React.Component {
componentDidMount() {
Actions.refresh({title: 'Chat'})
}
render() {
return (
<View style={{flex:1}}>
<ScrollView>
<View style={{flex: 1}}>
<Text>Hello !</Text>
</View>
</ScrollView>
<View style={{borderWidth: 1, padding:15}}>
<TextInput/>
</View>
</View>
)
}
}
export default Chat
The result is this very simple one:
But when my inputbox got focus, the inputbox still got stucked in the bottom of the screen, behind the keyboard. Any suggestion for this ?
One way would be to change your input's position when keyboard shows and hides.
You need to add two listeners for when keyboard shows and hides:
import { Keyboard } from 'react-native';
constructor(props) {
super(props);
this.state = {
keyboardHeight: 0,
inputHeight: 40
}
}
componentDidMount() {
Keyboard.addListener('keyboardDidShow', this._keyboardDidShow.bind(this));
Keyboard.addListener('keyboardDidHide', this._keyboardDidHide.bind(this));
}
_keyboardDidShow(e) {
this.setState({keyboardHeight: e.endCoordinates.height});
}
_keyboardDidHide(e) {
this.setState({keyboardHeight: 0});
}
render() {
return (
<TextInput style={{marginBottom: keyboardHeight + inputHeight}} />
)
}
You can also add some animation to make it move smoothly.
Another Suggestion would be :
React-Native-Keyboard-Aware-Scroll-View
This is great when you have multiples text inputs and does handle some animation. Not perfect but did the job for me.
I'm trying to use Canvas taken from https://github.com/iddan/react-native-canvas
However, when trying to generate, it seems that the WebView creates the following error:
Element type is invalid: expected a string (for built-in components) or a class/function (for composite components) but got: undefined. Check the render method of 'Canvas'
I've attached A snippet from the index.ios.js containing Canvas. Any help as to why the WebView generates this error would be super helpful (It works if you remove WebView and just leave View).
import React, { PropTypes, Component, WebView } from 'react';
import {
AppRegistry,
StyleSheet,
Text,
View,
TouchableOpacity,
Platform,
Image,
TouchableHighlight,
} from 'react-native';
import {
StackNavigator,
} from 'react-navigation';
import SignatureCapture from 'react-native-signature-capture';
const Sound = require('react-native-sound');
// TEST
class Canvas extends Component {
propTypes: {
context: React.PropTypes.object,
render: React.PropTypes.func.isRequired
};
render() {
var contextString = JSON.stringify(this.props.context);
var renderString = this.props.render.toString();
return (
<View>
<WebView
automaticallyAdjustContentInsets={false}
contentInset={{top: 0, right: 0, bottom: 0, left: 0}}
html={'<style>*{margin:0;padding:0;}canvas{position:absolute;transform:translateZ(0);}</style><canvas></canvas><script>var canvas = document.querySelector("canvas");(" + renderString + ").call(" + contextString + ", canvas);</script>'}
opaque={false}
underlayColor={'transparent'}
style={this.props.style}/>
</View>
);
};
};
What version of RN are you using? On 0.42 it says html prop is deprecated so you would have to use source={html: string, baseUrl: string}. Also I think it might be having trouble defining one of your jsx elements, I'm thinking it might be the
Try to add your html code in a file and call source={{ uri: require('./myfile.html')}} . Use source prop instead html. html is deprecated. Verify the docs https://facebook.github.io/react-native/docs/webview.html
I am working on tutorial for React Native navigation. I found out that all layout starts loading from top of screen instead of below of the status bar. This causes most layouts to overlap with the status bar. I can fix this by adding a padding to the view when loading them. Is this the actual way to do it? I don' think manually adding padding is an actual way to solve it. Is there a more elegant way to fix this?
import React, { Component } from 'react';
import { View, Text, Navigator } from 'react-native';
export default class MyScene extends Component {
static get defaultProps() {
return {
title : 'MyScene'
};
}
render() {
return (
<View style={{padding: 20}}> //padding to prevent overlap
<Text>Hi! My name is {this.props.title}.</Text>
</View>
)
}
}
Below shows the screenshots before and after the padding is added.
Now you can use SafeAreaView which is included in React Navigation:
<SafeAreaView>
... your content ...
</SafeAreaView>
There is a very simple way to fix this. Make a component.
You can create a StatusBar component and call it first after the first view wrapper in your parent components.
Here is the code for the one I use:
'use strict'
import React, {Component} from 'react';
import {View, Text, StyleSheet, Platform} from 'react-native';
class StatusBarBackground extends Component{
render(){
return(
<View style={[styles.statusBarBackground, this.props.style || {}]}> //This part is just so you can change the color of the status bar from the parents by passing it as a prop
</View>
);
}
}
const styles = StyleSheet.create({
statusBarBackground: {
height: (Platform.OS === 'ios') ? 18 : 0, //this is just to test if the platform is iOS to give it a height of 18, else, no height (Android apps have their own status bar)
backgroundColor: "white",
}
})
module.exports= StatusBarBackground
After doing this and exporting it to your main component, call it like this:
import StatusBarBackground from './YourPath/StatusBarBackground'
export default class MyScene extends Component {
render(){
return(
<View>
<StatusBarBackground style={{backgroundColor:'midnightblue'}}/>
</View>
)
}
}
I tried a more simple way for this.
We can get the height of Status Bar on android and use SafeAreaView along with it to make the code work on both platforms.
import { SafeAreaView, StatusBar, Platform } from 'react-native';
If we log out Platform.OS and StatusBar.currentHeight we get the logs,
console.log('Height on: ', Platform.OS, StatusBar.currentHeight);
Height on: android 24 and
Height on: android 24
We can now optionally add margin/padding to our container view using
paddingTop: Platform.OS === "android" ? StatusBar.currentHeight : 0
The final code in App.js is below:
export default class App extends React.Component {
render() {
return (
<SafeAreaView style={{ flex: 1, backgroundColor: "#fff" }}>
<View style={styles.container}>
<Text>Hello World</Text>
</View>
</SafeAreaView>
);
}
}
const styles = StyleSheet.create({
container: {
flex: 1,
backgroundColor: "#fff",
paddingTop: Platform.OS === "android" ? StatusBar.currentHeight : 0
}
});
#philipheinser solution does work indeed.
However, I would expect that React Native's StatusBar component will handle that for us.
It doesn't, unfortunately, but we can abstract that away quite easily by creating our own component around it:
./StatusBar.js
import React from 'react';
import { View, StatusBar, Platform } from 'react-native';
// here, we add the spacing for iOS
// and pass the rest of the props to React Native's StatusBar
export default function (props) {
const height = (Platform.OS === 'ios') ? 20 : 0;
const { backgroundColor } = props;
return (
<View style={{ height, backgroundColor }}>
<StatusBar { ...props } />
</View>
);
}
./index.js
import React from 'react';
import { View } from 'react-native';
import StatusBar from './StatusBar';
export default function App () {
return (
<View>
<StatusBar backgroundColor="#2EBD6B" barStyle="light-content" />
{ /* rest of our app */ }
</View>
)
}
Before:
After:
The react-navigation docs have a great solution for this. First off, they recommend not to use the SafeAreaView included with React Native because:
While React Native exports a SafeAreaView component, it has some
inherent issues, i.e. if a screen containing safe area is animating,
it causes jumpy behavior. In addition, this component only supports
iOS 10+ with no support for older iOS versions or Android. We
recommend to use the react-native-safe-area-context library to handle
safe areas in a more reliable way.
Instead, they recommend react-native-safe-area-context - with which it would look like this:
import React, { Component } from 'react';
import { View, Text, Navigator } from 'react-native';
import { useSafeArea } from 'react-native-safe-area-context';
export default function MyScene({title = 'MyScene'}) {
const insets = useSafeArea();
return (
<View style={{paddingTop: insets.top}}>
<Text>Hi! My name is {title}.</Text>
</View>
)
}
I would like to note that it's probably a better idea to use the SafeAreaView that this library offers though, since phones these days may also have elements at the bottom that can overlap UI elements. It all depends on your app of course. (For more detail on that, see the react-navigation docs I linked to in the beginning.)
Here is a way that works for iOS:
<View style={{height: 20, backgroundColor: 'white', marginTop: -20, zIndex: 2}}>
<StatusBar barStyle="dark-content"/></View>
You can handle this by adding a padding to you navigation bar component or just ad a view that has the same hight as the statusbar at the top of your view tree with a backgroundcolor like the facebook app does this.
Just Simple User React native Default StatusBar to achieve this funcationality.
<View style={styles.container}>
<StatusBar backgroundColor={Color.TRANSPARENT} translucent={true} />
<MapView
provider={PROVIDER_GOOGLE} // remove if not using Google Maps
style={styles.map}
region={{
latitude: 37.78825,
longitude: -122.4324,
latitudeDelta: 0.015,
longitudeDelta: 0.0121,
}}
/>
</View>
If you combine SaveAreaView and StatusBar, you get it.
https://reactnative.dev/docs/statusbar
https://reactnative.dev/docs/safeareaview
Just do this:
<SafeAreaView>
<View style={{flex: 1}}>
<StatusBar translucent={false} backgroundColor="#fff" />
// Your dark magic here
</View>
</SafeAreaView>
[This answer is applicable to Android emulators]
Hi, I have imported status bar from "react-native" and called it at the end of block with status bar style set to auto and it worked for me, the code below is for reference:
import { SafeAreaView,Button, StyleSheet, Text, TextInput, View } from 'react-native';
import { StatusBar } from 'react-native';
export default function App() {
return (
<SafeAreaView style={styles.appContainer}>
<View >
<TextInput placeholder='Add your course goal' />
<Button title="Add Goals" />
</View>
<View>
<Text>List of goals..</Text>
</View>
<StatusBar style="auto" />
</SafeAreaView>
);
}