fjmorant / react-native-nested-listview Goto Github PK
View Code? Open in Web Editor NEWDisplay nested arrays of N levels with this React Native library.
License: MIT License
Display nested arrays of N levels with this React Native library.
License: MIT License
Hello.
I installed it through npm i react-native-nested-listview
and I am getting an error:
could not resolve 'E:\mypath\node_modules\react-native-listview\dist\src\NestedListView as a file not as a folder'
when I looked at that folder there is no src folder inside the dist folder.
Is the installation file incomplete or am I doing something wrong?
NestedListView declares the type of the onNodePressed prop as () => any
This prop gets passed directly to NodeView which has an inconsistent signature: (item: any) => any
Neither signature is accurate to the actual usage of the onNodePressed prop. The only time where the prop is actually used is this line:
react-native-nested-listview/src/NodeView.tsx
Lines 60 to 62 in a747449
And the type of this.state.node
is INode
:
react-native-nested-listview/src/NodeView.tsx
Lines 26 to 27 in a747449
So the correct signature in all locations should be (node?: INode) => void
After the network request data is completed, the listview not refreshed when setState. My react native version is 0.50.3
Right now there is no so much info about this important element of the library
We need to search among all titles in react-native-nested-listview. However, I could't find any way to search in it. Can you please suggest me a way to do that? Thanks in advance.
Hello thanks for your plugin ๐
Is there a way to use your component from an object source like this?
{
name: 'Main Parent',
descendants: {
"1":{
name: "Main Child 1",
children: {
"1":{
name: "Sub Child 1",
children:{}
},
"2":{
name: "Sub Child 2",
children:{
name: "Sample",
children:{}
}
}
}
},
"2":{
name: "Main Child 2",
children: {
"1":{
name: "Sub Child 1",
children:{}
},
"2":{
name: "Sub Child 2",
children:{}
}
}
},
}
},
Right now, the only structure supported in children are arrays but to make the library more flexible I think it would be nice to support objects as well
I have a NestedListView that have checkboxes (using TouchableOpacity with Image that looks like a checkbox) in all of them.
When I click on the Checkbox in each NestedRow, the state changes as output in the componentWillUpdate
and render
methods, but the NestedRow itself isn't updating.
Here is a quick example I've whipped up from another issue.
The selected
array in the state is like
[
{
parent: false, //parent 0 value
child: [
false, // child 0 value
false
]
}
...etc
]
const generateXNumItems = (pid, numItems, prefix) => {
const items = []
let i
for (i = 0; i < numItems; i++) {
items.push({
name: `${prefix}.${i}`,
childId: i,
parentId: pid,
})
}
return items
}
const data = [
{
name: 'Item level 1.1',
parentId: 0,
descendants: generateXNumItems(0, 10, 'Item level 1.1'),
},
{
name: 'Item level 1.2',
parentId: 1,
descendants: generateXNumItems(1, 5, 'Item level 1.1'),
},
{
name: 'Item level 1.3',
parentId: 2,
descendants: generateXNumItems(2, 2, 'Item level 1.3'),
},
]
const colorLevels = {
[0]: 'white',
[1]: 'blue',
[2]: 'green',
[3]: 'red',
}
const styles = StyleSheet.create({
container: { flex: 1, backgroundColor: 'rgb(255, 255, 255)', padding: 15 },
node: {
flex: 1,
padding: 10,
borderWidth: 1,
borderColor: 'rgb(0, 0, 0)',
},
})
class ExampleApp extends Component {
constructor(props) {
// console.log(JSON.stringify(data));
super(props)
this.state = {
selected: []
}
}
componentWillMount() {
let selected = data.map(element => {
return {
parent: false,
child: Array(element.descendants.length).fill(false)
}
})
// console.log(JSON.stringify(selected));
this.setState({
... this.state,
selected: selected
});
}
toggleChecked(pid, cid = -1) {
let a = this.state.selected.slice(); //creates the clone of the state
if (cid === -1) {
a[pid].parent = !a[pid].parent;
} else {
a[pid].child[cid] = !a[pid].child[cid];
}
this.setState({
... this.state,
selected: a
});
}
componentWillUpdate(nextProp, nextState) {
console.log(JSON.stringify(nextState));
}
render() {
return (
<NestedListView
data={data}
getChildrenName={() => 'descendants'}
onNodePressed={category => {
}}
renderNode={(item, level) => {
switch (level) {
case 1:
return (
<NestedRow level={level} style={{ marginLeft: -10 }}>
<View
style={[
styles.node,
{
backgroundColor: colorLevels[level] || 'white',
paddingLeft: (level + 1) * 30,
},
]}>
<Text>{item.name}</Text>
<TouchableOpacity onPress={() => this.toggleChecked(item.parentId)}>
{
this.state.selected[item.parentId] ?
<Text>CHECKED</Text>
:
<Text>NOT CHECKED</Text>
}
</TouchableOpacity>
</View>
</NestedRow>
);
break;
case 2:
console.log(item.parentId, item.childId);
return (
<NestedRow level={level} style={{ marginLeft: -10 }}>
<View
style={[
styles.node,
{
backgroundColor: colorLevels[level] || 'white',
paddingLeft: (level + 1) * 30,
},
]}>
<Text>{item.name}</Text>
<TouchableOpacity onPress={() => this.toggleChecked(item.parentId, item.childId)}>
{
this.state.selected[item.parentId].child[item.childId] ?
<Text>CHECKED</Text>
:
<Text>NOT CHECKED</Text>
}
</TouchableOpacity>
</View>
</NestedRow>
);
break;
}
}}
/>
)
}
};
As you can see, when clicking on the TouchableOpacity
to change the state of the selected node from true to false and false to true (basically toggling), the componentWillUpdate
is shown to have updated the state (for example, clicking the first parent "CHECKED" will toggle the value), but the view itself is not rendering the updated value.
Thank you.
Edit:
https://www.youtube.com/watch?v=Cpp1hRQrgR0&feature=youtu.be
This will allow changing the UI depending on the state of the node
<NestedListView
style={{ height: '100%',flexGrow: 0 }}
data={devices}
getChildrenName={(node) => 'children'}
onNodePressed={(node) => {alert(node.name)
console.log(node)}}
renderNode={(node, level) => (
<NestedRow
// height = {0} //this shoud not be hard coded
level={level}
style={{ flexGrow:0,borderColor: 'black', borderWidth: 1}}
>
<DeviceRow cropType={node.cropType} gpm={node.gpm} name={node.name} status={node.status} />
</NestedRow>
most of the time we retrive the data from a service, and the data already has an ID value, and often is called id. This could conflict with node id you are generating, or have unnecessary double ids.
Consider adding a function to set the name of the current data ID.
When there's an error because something has not being provided, error messages are not well formatted
Be able to autoscroll to certain nodes if required
Now the NstedRow component has a fixed paddingLeft increment of ten times the current level as you can see in this code:
<View
style={[
styles.nestedRow,
{
...style,
height,
paddingLeft: level * 10,
},
]}>
{children}
</View>
Now then is fixed, you should be able to set the paddingLeftIncrement per level
it would be nice to have a list of all selected (opened) values of the list as selectedValues
and the last clicked node as currentValue, so that we can give e visual feedback on which node is currently selected.
This will simplify the fact of creating simple lists
Will fix this issue #50
Allow users to programmatically expand or contract a node without user interaction
ERR! git .../node_modules/react-native-nested-listview: Appears to be a git repo or submodule.
...
"react-native-nested-listview": "^0.7.1",
...
Is there a way to prevent all nested rows to close on press calling setState?
I have a list that I want to allow a press that changes the style of the nested row without closing it
can I add icon in the right of NestedListView?
When using this library, we currently receive the following warnings as of RN 0.61:
WARN Warning: componentWillMount has been renamed, and is not recommended for use. See https://fb.me/react-async-component-lifecycle-hooks for details.
* Move code with side effects to componentDidMount, and set initial state in the constructor.
* Rename componentWillMount to UNSAFE_componentWillMount to suppress this warning in non-strict mode. In React 17.x, only the UNSAFE_ name will work. To rename all deprecated lifecycles to their new names, you can run `npx react-codemod rename-unsafe-lifecycles` in your project source folder.
Please update the following components: NestedListView, NodeView
WARN Warning: componentWillReceiveProps has been renamed, and is not recommended for use. See https://fb.me/react-async-component-lifecycle-hooks for details.
* Move data fetching code or side effects to componentDidUpdate.
* If you're updating state whenever props change, refactor your code to use memoization techniques or move it to static getDerivedStateFromProps. Learn more at: https://fb.me/react-derived-state
* Rename componentWillReceiveProps to UNSAFE_componentWillReceiveProps to suppress this warning in non-strict mode. In React 17.x, only the UNSAFE_ name will work. To rename all deprecated lifecycles to their new names, you can run `npx react-codemod rename-unsafe-lifecycles` in your project source folder.
Please update the following components: NestedListView, NodeView
these guidelines should be followed and an update should be applied to this lib
Folders and files to be ignore in npmignore:
Hey,
really neat library you got here! My only problem so far, is when I want to change my data structure via setState(), the whole list collapses, and I have to start opening everything again.
Is there a way to go around this? (I couldn't find any similar cases in the examples, nor the Issues on github.
export default class ExampleApp extends React.Component {
state = {
currentList: data
}
getChildrenName = node => {
return 'children';
}
addItem = () => {
this.setState({
currentList: [
...this.state.currentList.slice(0, 0), // 2018 year
{
...this.state.currentList[0],
children: [
...this.state.currentList[0].children.slice(0, 0), // oktober first month
{
...this.state.currentList[0].children[0],
children: [
...this.state.currentList[0].children[0].children.slice(0, 0),
{
name: 'SORELEJE'
},
...this.state.currentList[0].children[0].children.slice(1)
]
},
...this.state.currentList[0].children.slice(1)
]
},
...this.state.currentList.slice(1)
]
})
}
renderItem = (node, level) => {
console.log('Level', level);
return (
<View
style={{ paddingLeft: 12, flexDirection: 'row', alignItems: 'center' }}
>
<Text style={{ marginRight: 24 }}>{node.name}</Text>
{level == 2 && (
<TouchableOpacity onPress={this.addItem} >
<Icon name="add" size={30} />
</TouchableOpacity>
)}
</View>
);
};
render() {
return (
<View style={styles.container}>
<NestedListView
data={this.state.currentList}
getChildrenName={this.getChildrenName}
renderNode={(node, level) => (
<NestedRow
level={level}
paddingLeftIncrement={0}
style={{ borderColor: 'black', borderWidth: 1 }}
>
{this.renderItem(node, level)}
</NestedRow>
)}
/>
</View>
);
};
}
Thanks for this module, one question, are you planning adding onChildrenPressed method?
Hello :)
Just want to ask if there is a plan for the nested list view to have an Accordion like behavior. It would be better if there is an option that we can close other list if a list header of it's same level is clicked. If it isn't too much to ask. Thanks.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.