I am new in world of react native and i want to show side menu from left in my application and i am using react-native-navigation to do so but i am facing sum problem with this
firstly i set the navigation root like below :-
Navigation.setRoot({
root: {
bottomTabs: {
children: [
{
stack: {
children: [
{
component: {
name: "FindPlace",
options: {
bottomTab: {
text: "find place",
icon: response[0],
},
topBar: {
title: {
text: "find place"
},
leftButtons: [
{
icon: response[2],
id: 'leftSideDrawer',
},
],
}
}
}
}
]
}
},
],
},
sideMenu: {
left: {
component: {
name: 'SideDrawer',
id: 'leftSideDrawer'
}
},
},
}
})
where i declare both bottomTabs and sideMenu and i add a button which trigger event on findPlace component where i add an Navigation.event() listner that toggle visiblity of my left sideMenu like below :-
constructor(props) {
super(props);
Navigation.events().bindComponent(this)
}
navigationButtonPressed({ buttonId }) {
Navigation.mergeOptions('leftSideDrawer', {
sideMenu: {
left: {
visible: true
}
}
});
}
but this is not working at all and it just show an blank screnn and if iremove the sideMenu section from setRoot it will show me the bottomTabs and when i add sideMenu again it show me a blank scrennd.
there is no examples regariding this on RNN version 2 docs i search alot by i didn't find anything that help me with this so please let me know what i am doing wrong so i can get out of this stuff
thanks in advance !!
It works by putting the bottomTabs inside the sideMenu which is at the root of the hierachy. Also the sideMenu has a center field which is required. The docs says:
center is required and contains the main application, which requires to have a topBar aka stack.
The code must be implemented like the following:
Navigation.setRoot({
root: {
sideMenu: {
left: {
component: {
id: "leftSideDrawer",
name: "SideDrawer"
}
},
center: {
bottomTabs: {
children: [
{
component: {
name: "FindPlace",
options: {
bottomTab: {
text: "find place",
icon: response[0]
},
topBar: {
title: {
text: "find place"
},
leftButtons: [
{
icon: response[2],
id: "leftSideDrawer",
},
],
}
}
}
}
],
}
}
}
}
});
Use this structure to make it works. Please, notice that if you need to push other screens then you need to use a stack.
Related
I have a Storybook project and a component that looks like this:
export default {
title: 'MDButton',
argTypes: {
label: {
name: "Label",
defaultValue: "Button",
control: {
type: "text"
}
},
disabled: {
name: "Disabled",
defaultValue: false,
control: {
type: "boolean"
}
}
}
};
These are the stories:
export const Default = Template.bind({});
Default.args = {};
export const WithDisabled = Template.bind({});
WithDisabled.args = {};
I want the first story to not have the disabled arg.
Is that possible?
I know I can go over args and filter out the things I don't want, but what if I have tons of args?
You can disable specific arg prop with a next code. Example in MDX-format.
<Meta
title="Title"
component={YourComponent}
argTypes={{
icon: { table: { disable: true } },
label: { table: { disable: true } },
onClick: { table: { disable: true } },
}}
/>
Good luck!
I am working with ckeditor4-react plugin to use Text editor inside react app. Now I want to add a string dropdown inside my text editor, for this I have followed the "add custom plugin" documentation and added "strinsert" custom plugin.
Inside "node-modules/ckeditor4-react/" folder I have created a folder with name "plugins" and placed "strinsert" folder inside this.
Now my path of custom plugins is "node-modules/ckeditor4-react/plugins/strinsert/plugin.js"
Code of "plugin.js":
CKEDITOR.plugins.add('strinsert',
{
requires : ['richcombo'],
init : function( editor )
{
// array of strings to choose from that'll be inserted into the editor
var strings = [];
strings.push(['##FAQ::displayList()##', 'FAQs', 'FAQs']);
strings.push(['##Glossary::displayList()##', 'Glossary', 'Glossary']);
strings.push(['##CareerCourse::displayList()##', 'Career Courses', 'Career Courses']);
strings.push(['##CareerProfile::displayList()##', 'Career Profiles', 'Career Profiles']);
// add the menu to the editor
editor.ui.addRichCombo('strinsert',
{
label: 'Insert Content',
title: 'Insert Content',
voiceLabel: 'Insert Content',
className: 'cke_format',
multiSelect:false,
panel:
{
css: [ editor.config.contentsCss, CKEDITOR.skin.getPath('editor') ],
voiceLabel: editor.lang.panelVoiceLabel
},
init: function()
{
this.startGroup( "Insert Content" );
for (var i in strings)
{
this.add(strings[i][0], strings[i][1], strings[i][2]);
}
},
onClick: function( value )
{
editor.focus();
editor.fire( 'saveSnapshot' );
editor.insertHtml(value);
editor.fire( 'saveSnapshot' );
}
});
}
});
After adding this I have used this plugin inside Text editor by using "extraPlugins" config prop. This is a code of my TextEditor plugin file(which is inside the "src" folder of )
class TextEditor extends React.Component {
constructor(props) {
super(props);
this.state = {
editorData: this.props.data
}
}
/** lifecycle method */
componentDidMount() {
this.isMount = true;
this.setState({editorData: this.props.data})
}
componentWillUnmount() {
this.isMount = false;
}
/** function to detect the editor changes */
onEditorChange(event) {
let data = event.editor.getData()
this.props.onChange(data)
}
// main function
render() {
const { editorData } = this.state;
return (
<CKEditor
data={editorData}
onChange={(e) => this.onEditorChange(e)}
config={{
toolbar: [
{ name: 'basicstyles', items: ['Bold', 'Italic', 'Underline', 'Strike'] },
{ name: 'editing', items: ['SelectAll'] },
{ name: 'clipboard', items: ['Undo', 'Redo'] },
{ name: 'links', items: ['Link', 'Unlink', 'Anchor'] },
{ name: 'insert', items: [ 'Image', 'Table', 'HorizontalRule', 'Smiley', 'SpecialChar' ] },
{ name: 'document', items: [ 'Templates', 'Preview', '-', 'Source'] },
{ name: 'paragraph', items: ['NumberedList', 'BulletedList', '-', 'Outdent', 'Indent', 'Blockquote', '-', 'JustifyLeft', 'JustifyCenter', 'JustifyRight', 'JustifyBlock', '-', 'BidiLtr', 'BidiRtl', 'Language'] },
{ name: 'styles', items: [ 'Styles', 'Format', 'Font', 'FontSize' ] },
{ name: 'colors', items: [ 'TextColor', 'BGColor' ] },
{ name: 'tools', items: [ 'Maximize', 'ShowBlocks' ] },
],
removePlugins: ['language'],
extraPlugins: "strinsert",
}}
/>
);
}
}
export { TextEditor };
After adding this when I am opening the text editor it shows me an error inside console::
Error::
ckeditor.js:98 GET https://cdn.ckeditor.com/4.15.1/standard-all/plugins/strinsert/plugin.js?t=KA9B
ckeditor.js:258 Uncaught Error: [CKEDITOR.resourceManager.load] Resource name "strinsert" was not found at "https://cdn.ckeditor.com/4.15.1/standard-all/plugins/strinsert/plugin.js?t=KA9B".
at window.CKEDITOR.window.CKEDITOR.dom.CKEDITOR.resourceManager.<anonymous> (ckeditor.js:258)
at n (ckeditor.js:253)
at Array.v (ckeditor.js:254)
at y (ckeditor.js:254)
at HTMLScriptElement.CKEDITOR.env.ie.g.$.onerror (ckeditor.js:255)
Please suggest how can I add "strinsert" custom plugin inside ckeditor4-react text editor.
When using the Microsoft sample code for the React Office Fabric UI I am getting the error.
TS6133: 'event' is declared but its value is never read.
Code:
https://developer.microsoft.com/en-us/fabric#/controls/web/dropdown
Code Pen: (No Error)
https://codepen.io/pen/?&editable=true
import * as React from 'react';
import { Dropdown, DropdownMenuItemType, IDropdownOption } from 'office-ui-fabric-react/lib/Dropdown';
export interface IDropdownControlledMultiExampleState {
selectedItems: string[];
}
export class DropdownControlledMultiExample extends React.Component<{}, IDropdownControlledMultiExampleState> {
public state: IDropdownControlledMultiExampleState = {
selectedItems: []
};
public render() {
const { selectedItems } = this.state;
return (
<Dropdown
placeholder="Select options"
label="Multi-select controlled example"
selectedKeys={selectedItems}
onChange={this._onChange}
multiSelect
options={[
{ key: 'fruitsHeader', text: 'Fruits', itemType: DropdownMenuItemType.Header },
{ key: 'apple', text: 'Apple' },
{ key: 'banana', text: 'Banana' },
{ key: 'orange', text: 'Orange', disabled: true },
{ key: 'grape', text: 'Grape' },
{ key: 'divider_1', text: '-', itemType: DropdownMenuItemType.Divider },
{ key: 'vegetablesHeader', text: 'Vegetables', itemType: DropdownMenuItemType.Header },
{ key: 'broccoli', text: 'Broccoli' },
{ key: 'carrot', text: 'Carrot' },
{ key: 'lettuce', text: 'Lettuce' }
]}
styles={{ dropdown: { width: 300 } }}
/>
);
}
private _onChange = (event: React.FormEvent<HTMLDivElement>, item: IDropdownOption): void => {
const newSelectedItems = [...this.state.selectedItems];
if (item.selected) {
// add the option if it's checked
newSelectedItems.push(item.key as string);
} else {
// remove the option if it's unchecked
const currIndex = newSelectedItems.indexOf(item.key as string);
if (currIndex > -1) {
newSelectedItems.splice(currIndex, 1);
}
}
this.setState({
selectedItems: newSelectedItems
});
};
}
My use is no different, just implemented outside codepen. I have found the same with all the sample code. What else should be used to utilize the event?
You shouldn't really force yourself to utilize it. An example might be where the _onChange handler is being used for bunch of other forms as well and a need might arise to look into the event object to see where is it coming from etc..
See here: Ignore TS6133: "(import) is declared but never used"?
You need to turn-off the noUnusedLocals option from your tsconfig.json for the error to disappear.
I am using react native navigation to start a tab based app, here is the code
Navigation.startTabBasedApp({
tabs: [
{
screen: "Starnote.CategoriesActivity",
title: 'Categories',
icon: require('../../assets/tabs/cat.png'),
selectedIcon: require('../../assets/tabs/cat_act.png')
},
{
screen: "Starnote.JobsActivity",
title: 'Jobs',
icon: require('../../assets/tabs/job.png'),
selectedIcon: require('../../assets/tabs/job_act.png')
},
{
screen: "Starnote.FavsActivity",
title: 'Favourites',
icon: require('../../assets/tabs/heart.png'),
selectedIcon: require('../../assets/tabs/heart_act.png')
},
{
screen: "Starnote.SeachActivity",
title: 'Favourites',
icon: require('../../assets/tabs/search.png'),
selectedIcon: require('../../assets/tabs/search_act.png')
},
{
screen: "Starnote.ProfActivity",
title: 'Favourites',
icon: require('../../assets/tabs/prof.png'),
selectedIcon: require('../../assets/tabs/prof_act.png')
}
],
tabsStyle: {
tabBarBackgroundColor: '#1f2533',
tabBarSelectedButtonColor: '#f6a821',
}
})
The tabs contain the icons but there height is greater then the tab bar, how can i fix this, here is the picture of tab bar created through this code,
Use -
options: {
bottomTab: {
fontSize: 12
}
}
add fontSize option
I am using react native navigation by wix for my application.
It is working fine if I just have the Navigation.startTabBasedApp in my application like this:
import React, { Component } from 'react';
import Amplify from 'aws-amplify-react-native';
import { Navigation } from 'react-native-navigation';
import { registerScreens } from './screens';
import aws_exports from './aws-exports';
Amplify.configure(aws_exports);
registerScreens();
return Navigation.startTabBasedApp({
tabs: [
{
label: 'Home',
screen: 'pumped.HomeScreen',
title: 'Pumped',
},
{
label: 'Sell',
screen: 'pumped.ListScreen',
title: 'Sell an item',
},
{
label: 'Profile',
screen: 'pumped.ProfileScreen',
title: 'Profile',
},
],
});
However I want to render either a single screen or this tab based app conditionally based on wether the user is signed in or not. But when i add the two inside a app component and return either one based on a condition (true in my code just for testing) it doesn't return anything?
Here is my code:
import React, { Component } from 'react';
import Amplify from 'aws-amplify-react-native';
import { Navigation } from 'react-native-navigation';
import { registerScreens } from './screens';
import aws_exports from './aws-exports';
Amplify.configure(aws_exports);
registerScreens();
class App extends Component {
render() {
if (true) {
return Navigation.startSingleScreenApp({
screen: {
screen: 'pumped.RegisterScreen',
navigatorStyle: {},
navigatorButtons: {},
title: 'Register',
},
});
}
return Navigation.startTabBasedApp({
tabs: [
{
label: 'Home',
screen: 'pumped.HomeScreen',
title: 'Pumped',
},
{
label: 'Sell',
screen: 'pumped.ListScreen',
title: 'Sell an item',
},
{
label: 'Profile',
screen: 'pumped.ProfileScreen',
title: 'Profile',
},
],
});
}
}
export default App;
Thanks.
Try wrapping your returns in parentheses.
if (true) {
return (
Navigation.startSingleScreenApp({
screen: {
screen: 'pumped.RegisterScreen',
navigatorStyle: {},
navigatorButtons: {},
title: 'Register',
},
})
);
}
return (
Navigation.startTabBasedApp({
tabs: [
{
label: 'Home',
screen: 'pumped.HomeScreen',
title: 'Pumped',
},
{
label: 'Sell',
screen: 'pumped.ListScreen',
title: 'Sell an item',
},
{
label: 'Profile',
screen: 'pumped.ProfileScreen',
title: 'Profile',
},
],
})
);
I have a similar approach as you. I am using aws-amplify (but not their HOC components) and redux.
See this blog for more info with redux:
https://medium.com/react-native-training/explanation-of-react-native-navigation-wix-with-redux-deabcee8edfc
export default class App extends React.Component {
constructor(props: any) {
super(props);
store.subscribe(this.onStoreUpdate);
store.dispatch({ type: 'INIT' }); // Trigger the onStoreUpdate function
}
onStoreUpdate = () => {
const newLoginState = store.getState().get('auth').get('loginState');
if (this.currentLoginState !== newLoginState) {
this.currentLoginState = newLoginState;
this.startApp(this.currentLoginState);
}
}
startApp = (loginState: string) => {
switch(loginState) {
case 'signedOut':
startLoginSingleScreen();
return;
case 'signedIn':
startHomeTabs();
return;
default:
console.log('Root not found!');
}
}
}
and in my index.ios.js and index.android.js:
import App from './App';
const app = new App();