GeekyAnts / GeekyAnts/NativeBase
Set arbitrary data on View
- Dominant language
- TypeScript
- Stars
- 20.4k
- Forks
- 2.4k
- PR merge metrics
- No merged PRs in 30d
Description
### Description
I would like a way to tag a view with arbitrary data which can be inspected later.
For example, when pressing on a cell in a grid, the event passed to the onPress handler should have some attribute by which I can tell what kind of view it was.
### Problem Statement
Currently, I can't tell how to handle events in more complicated setups. In the grid example, I might want to handle onPress events differently, depending on what type of cell the user clicked on. But as it is, all cells are treated the same. I can tell the user clicked on a cell, but I can't tell what _type_ of cell it was.
### Proposed Solution or API
Could be as simple as:
```
{
switch(e.target.viewData.type) {
case 'type1':
// do something
break;
case 'type2':
// do something else
break;
case 'type3':
// do yet another thing
break;
}
}}>
```
### Alternatives
In ReactJS, I would simply give a div a className, or some data-* attribute, but I don’t seem to be able to do either with NativeBase. I understand this is probably because ReactNative doesn't use divs, and NativeBase has to work on both web and mobile. But it would make sense for there to be _some_ mechanism to do this, which works on both mobile and web platforms.
### Additional Information
_No response_
Contributor guide
Assessment
This issue has not been assessed yet.