How to hide back button of React Native navigator - uinavigationcontroller

I have made a login button which will jump to main-ui. I don't want people to see the back button at top-left position of navigator's default style.
It seems that NavigatorIOS has no suitable API to use. Can you give me some idea?

You'll have to use Navigator. I recommend using it in conjunction with React Native Navbar.
With Navbar, you can pass in the right and left button components... Or just make them an empty view, if they shouldn't be visible. The property is leftButton and rightButton.
The navigator example on the React docs should get you started:
<Navigator
initialRoute={{name: 'My First Scene', index: 0}}
renderScene={(route, navigator) =>
<MySceneComponent
name={route.name}
onForward={() => {
var nextIndex = route.index + 1;
navigator.push({
name: 'Scene ' + nextIndex,
index: nextIndex,
});
}}
onBack={() => {
if (route.index > 0) {
navigator.pop();
}
}}
/>
}
/>
Now in the definition of MySceneComponent you would include displaying NavBar:
const MySceneComponent = (props) => (
<View style={{ flex: 1, }}>
<NavigationBar
title={titleConfig}
rightButton={BUTTON_OR_NOT}
{...props} />
{props.children}
</View>
);
Of course you will want to abstract your navigation bits perhaps into a component which displays the navigation bar around it as I have shown above with the display of {children}. You will further want to pass the route and navigation information into Navbar so it can display the page information and make it so that clicking on the back button calls navigator.pop(), which is what I did by passing on props via {...props}.

Related

How to make React MUI Components resize correctly

I have a page that has table component. Inside this table component are a DataGrid, and 2 button components, all using Material UI. I also have a navbar component that uses the MUI AppBar component with a button group. I originally developed this app on my extra large monitor and everything looked find, but as soon as I moved it to a regular monitor, I noticed that the navbar and DataGrid table were not scaling properly and that my buttons disappear underneath the footer.
If I 'scrunch' or reduce the browser window, a scrollbar appears, but its outside the table. I am not making this app for mobile so I just need it to display properly in common computer screen sizes. I want to focus on the table and buttons first. I have tried to put the button's outside the Table component, but I get the same result, so I am going to leave them inside the table component for now. I have already tried to wrap the table component in a div using display: 'flex' but it doesn't seem to change anything. Any suggestions on what I can do to get this to display properly? Is there a way to wrap everything in the App.js to get responsive action for all components?
import React, { useState, useEffect } from 'react';
import { DataGrid, GridToolbar} from '#mui/x-data-grid';
import EditJobModal from './EditJobModal';
import ClearButton from './ClearButton';
const MyTable = ({columns, data, clearStatus}) => {
const [selectionModel, setSelectionModel] = useState([]);
const [selectedRows, setSelectedRows] = useState([{'id': ''}]);
const buttonToTable = (clearStatus) => {
if (clearStatus === true) {
setSelectionModel([]);
setSelectedRows([{'id': ''}]);
}
}
return (
<div style={{ height: 450, width: '100%' }}>
<div style={{ display: 'flex', height: '100%' }}>
<div style={{ flexGrow: 1 }}>
<DataGrid
sx={{
boxShadow: 2,
border: 1,
margin: '5px'
}}
columns={columns}
rows={data}
pageSize={5}
rowsPerPageOptions={[10]}
checkboxSelection={false}
components={{ Toolbar: GridToolbar }}
selectionModel={selectionModel}
onSelectionModelChange={(ids) => {
if (ids.length > 1) {
let selectionSet = new Set(selectionModel);
let result = ids.filter((s) => !selectionSet.has(s));
setSelectionModel(result);
} else {
let selectedIDs = new Set(ids);
console.log(selectedIDs);
let selectedRow = data.filter((row) =>
selectedIDs.has(row.id),
);
setSelectedRows(selectedRow);
setSelectionModel(ids[0]);
}
}}
/>
<EditJobModal jobData={selectedRows}/>
<ClearButton buttonToTable={buttonToTable}/>
</div>
</div>
</div>
);
};
export default MyTable;

Toggle Function Using 2 Separate Buttons in 2 Different Components for Mobile Navigation

I have a button in the Header component to toggle the mobile nav open and that is working fine. I have a instance of this button within the mobile menu that I want to close the mobile nav. Clicking the 2nd instance of the mobile nav toggle button in the mobile nav gives an error: Typeerror toggleMobile is not a function
I know I can make this work with a single instance of the button, but would really like to figure out how to get this working with two instances of the button.
Here is simplified code from the 3 components involved.
Simplified Header.js - this part is working as expected
export default function Header() {
const [mobileOpen, setMobileOpen] = useState(false)
const toggleMobile = (toggleValue) => {
setMobileOpen(toggleValue)
}
return (
<Box>
{mobileOpen && <MobileNav toggleMobile={toggleMobile} />}
<MobileIcon toggleMobile={toggleMobile} toggleValue={true} />
</Box>
)
}
MobileIcon component - this works when triggered from the Header component
function MobileIcon({ toggleMobile, toggleValue }) {
return (
<Link href="#">
<Icon
onClick={() => toggleMobile(toggleValue)}
display={{base: 'flex', md: 'none'}}
as={RiMenu2Line} w={8} h={8} mr={8}>
</Icon>
</Link>
)
}
export default MobileIcon;
Simplified MobileNav component - this is the problem. Both Header and MobileNav components are rendering the same MobileIcon component
function MobileNav( toggleMobile ) {
return (
<MobileIcon toggleMobile={toggleMobile} toggleValue={false}/>
)
}
export default MobileNav;
Clicking this instance of the MobileIcon gives the error: 'TypeError: toggleMobile is not a function' and references the toggleMobile function in the MobileIcon component.
I'm guessing this has something to do with how I'm passing the function reference twice in Header. I've tried a lot of different solutions, and can't figure it out.

Scroll Sync mapped components

I'm trying to scroll sync my mapped components in react.
I have tried couple scroll sync libraries but I don't think they work on mapped components.(I would appreciate it if someone could help me out using scroll sync libraries. I have tried placing scrollSyncNode / scrollSyncPane inside the map function wrapping the component but it doesn't work.)
The below are two functions which I made where ref1 and ref2 scroll at the same time. I have tested the function with two independent components(not mapped) and they work fine.
I'm not completely sure if its possible but I want all the mapped components to equally share ref2.
the onScroll event will trigger the function.
I would really appreciate it if someone could give me a thorough guide to how I could scroll sync an independent component with the mapped components.
below is my parent component's code where both the independent component and mapped components are located:
const refOne = useRef();
const refTwo = useRef();
const handleScrollFirst = scroll => {
refTwo.current.scrollLeft = scroll.target.scrollLeft;
};
const handleScrollSecond = scroll => {
refOne.current.scrollLeft = scroll.target.scrollLeft;
};
return (
<ContentsWrapper>
<ThisIsRefOneDiv
style={{
width: '5vw',
overflowX: 'scroll',
}}
onScroll={handleScrollFirst}
ref={div1}
>
testtesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttest
</ThisIsRefOneDiv>
{data.map((group, idx) => (
<Card key={idx} color={group.color}>
<Objective data={group} />
{state && (
<Content>
<GanttData
data={group}
**onScroll={handleScrollSecond}
ref={refTwo}
/>
</Content>
)}
</Card>
))}
</ContentsWrapper>
);
}

CSS for Drop down list popup based on the position that click on the mobile device

I am new to React.js. We use the material-io CSS framework to build our app.
I have a task to display menu items of in a dropdown menu, which opens to the top or bottom based on the position of the menu when it is opened on a mobile device..
It is similar to the Facebook video section when the user clicks the (...)-icon it shows the options based on the screen position of the icon.
Facebook bottom appear]2
Facebook menu bottom appear
You can make use of a library that provides a tooltip menu. For example https://justinrhodes1.github.io/react-power-tooltip/
You Can Use react-power-tooltip. For Use:
Install From Npm
$ npm install react-power-tooltip --save
import To Project
import Tooltip from 'react-power-tooltip'
Add a hover state & mouse event handler to the enclosing target component
class Test extends Component {
state = {
show: false
}
showTooltip = bool => {
this.setState({ show: bool })
}
render() {
return (
{/* Target element position needs to be RELATIVE */}
<div
style={{ position: 'relative' }}
onMouseOver={() => this.showTooltip(true)}
onMouseLeave={() => this.showTooltip(false)}>
{/* ADD TOOLTIP HERE */}
</div>
);
}
}
export default Test;
Add the tooltip inside the target element
{/* Add options/text via span elements */}
<Tooltip show={this.state.show}>
<span>Some text</span>
</Tooltip>
For More Information:
https://justinrhodes1.github.io/react-power-tooltip/

How to style React Native <CheckBox> component?

Is it possible to style the React Native CheckBox component?
There is no style property listed here: https://facebook.github.io/react-native/docs/checkbox.html
I put an invalid style property on it, and the RN warning message that popped up told me all the valid CSS properties, but none of them did anything beneficial towards styling.
The component looks decent, but I want to change it from that teal color to a brand color.
Is it possible?
These properties are not working but are listed as valid style props for CheckBox:
{
height: 50, // changes the hitspace but not the checkbox itself
width: 50,
borderWidth: 1, // does nothing
backgroundColor: 'red', // makes the area around and inside the checkbox red
borderColor: 'green', // does nothing
borderStyle: 'dotted' // does nothing
}
I don't understand why it even exists if everyone just makes their own checkbox. If I did that, I wouldn't really have any use for because all it gives is
value={this.state.rememberMe}
onValueChange={() => this.toggleRememberMe()}
unless there is something magic it does under the hood. It has a decent onChange animation, but that would be deprecated instantly when I make my own and use something like <TouchableHighlight or Opacity> wrapped around an on/off image or <View>.
I can't find any info on Google except hundreds of custom checkboxes. It's actually really hard to search around them.
You can use https://github.com/react-native-community/react-native-checkbox
Android: you can use tintColors.
import CheckBox from '#react-native-community/checkbox';
.
.
.
<CheckBox
value={option.item.selected}
onValueChange={() => {}}
tintColors={{ true: '#F15927', false: 'black' }}
/>
Transform can be used to change CheckBox size.
<CheckBox
style={{ transform: [{ scaleX: 0.8 }, { scaleY: 0.8 }] }}
/>
checkbox examples
https://github.com/react-native-checkbox/react-native-checkbox
No I couldn't find a way, but wrapping it in a View was one option:
<View style={{
position: 'absolute',
right: 0,
width: 50,
height: 50,
margin: 10,
zIndex: 100,
}}>
<Checkbox
status={i === index ? 'checked' : 'unchecked'}
className=""
/>
</View>
Short answer is you simply can't. React Native uses the native Android Checkbox component, and the only customization you get to do is changing the tint colors, as seen in the react-native-checkbox community project. This prop is undocumented in the official React Native docs.
Additionally, here's the TypeScript definition for this component: AndroidCheckBoxNativeComponent.js. Notice how the only props relayed to the native component are onChange, onValueChange, testID, on, enabled and tintColors.
Yes, you can, i recommend you that use react native elements, and with this library you have 2 options, checkedColor and uncheckedColor, by default in checkedColor is green, but you can change it to what you want, for example, checkedColor={"#fff"} or checkedColor="#fff" try them, it apply for 2 options, good luck!
For IOS use onTintColor and pass the value in string onTintColor={'red'}
<CheckBox
onTintColor={Color.theme}
onCheckColor={Color.theme}
value={isSelected}
onValueChange={setSelection}
style={Style OBJECT}
/>
import CheckBox from '#react-native-community/checkbox';
const Checkbox = (props) => {
// const [isSelected, setSelection] = useState(false);
const [toggleCheckBox, setToggleCheckBox] = useState(false)
return (
<View style={[useTailwind``, styles.container]}>
<View style={styles.checkboxContainer}>
<CheckBox
disabled={false}
value={toggleCheckBox}
tintColors={{true: '#368098'}}
onCheckColor={'#6F763F'}
onValueChange={(newValue) => setToggleCheckBox(newValue)}
/>
<Text style={[useTailwind`font-normal text-base font-sans`, styles.label]}>{props.value}</Text>
</View>
{/* <Text>Is CheckBox selected: {isSelected ? "👍" : "👎"}</Text> */}
</View>
);
};
its possible now..
just simply gives tint color of the same color of background

Resources