Comments (8)
@SteffenC rather than calling a local function on the list component, I make each item it's own component.
In my main component (the list):
render: function() {
return (
<View style={gStyles.listViewMax}>
<ListView
dataSource={this.state.dataSource}
renderRow={this.renderAlert}
style={gStyles.jobListView}
/>
</View>
);
},
renderAlert: function(job) {
return (<AlertListItem alertKeyType={this.state.alertKeyType} job={job} />);
},
My AlertListItem.js (Component)
render: function() {
var myButtons = null;
if(this.state.read) {
myButtons = [
{
text: 'Mark as Unread',
backgroundColor: '#FCA612',
color:'white',
onPress: () => {
this.markRead('markunread');
},
}
];
} else {
myButtons = [
{
text: 'Mark as Read',
backgroundColor: '#FCA612',
color:'white',
onPress: () => {
this.markRead('markread');
},
}
];
}
let swipeoutBtns = myButtons;
return (<Swipeout autoClose={true} job={this.props.job} right={swipeoutBtns}>
<View style={gStyles.alertListViewItemContainer}>
<View style={gStyles.alertListViewItemContainerButton}>
<View style={gStyles.alertListViewItemPersonalDetails}>
<Text style={gStyles.alertListViewItemName}>{this.props.job.firstname} {this.props.job.lastname}</Text>
<Text style={gStyles.alertListViewItemNote}>{this.props.job.note}</Text>
<Text style={gStyles.alertListViewItemTimeAgo}>{this.props.job.datetime}</Text>
</View>
<View style={gStyles.alertListViewItemReadFlag}>
{this.readOrNot()}
</View>
</View>
</View>
</Swipeout>);
... in this way I can use the props or the state on the component to store anything I want about that particular list item.
from react-native-swipeout.
Ok so I think I figured out an approach.
`
renderRow: function(rowData) {
let swipeoutBtns = [
{
text: 'Mark as read',
onPress: () => {
this.markAsRead(rowData);
},
}
];
return (
<Swipeout autoClose={true} right={swipeoutBtns}>
// ... rest of your row render function
`
from react-native-swipeout.
It's so simple, the solution is here
` right: [
{
onPress: () => {
const deletingRow = this.state.activeRowKey;
const jsonData = this.state.jsonData;
Alert.alert(
'Delete',
'Are you sure you want to delete ?',
[
{ text: 'No', onPress: () => console.log('Cancel Pressed'), style: 'cancel' },
{
text: 'Yes', onPress: () => {
jsonData.splice(this.props.index, 1);
this.props.parentFlatList.refreshFlatList(deletingRow);
}
},
],
{ cancelable: true }
);
},
component: <SwipeDelete />,
},
],`
from react-native-swipeout.
@bfarrgaynor Could you share a bit more of your code ? I'm having the same issue, and can't quite see how this should work
from react-native-swipeout.
@bfarrgaynor Beautiful ! Thank you very much!
from react-native-swipeout.
How to pass the onPress function as a prop to the custom component, here I tried some but not working
` right: [
{
onPress() {
const deletingRow = this.state.activeRowKey;
const jsonData = this.state.jsonData;
Alert.alert(
'Delete',
'Are you sure you want to delete ?',
[
{ text: 'No', onPress: () => console.log('Cancel Pressed'), style: 'cancel' },
{
text: 'Yes', onPress: () => {
jsonData.splice(this.props.index, 1);
this.props.parentFlatList.refreshFlatList(deletingRow);
}
},
],
{ cancelable: true }
);
},
component: <SwipeDelete onPressFun={onPress()} /> // here to pass above onPress() ?
}
],
`
from react-native-swipeout.
@rsp8055
Could you please create a demo for the same on "https://expo.io/snacks" ?.
It would be very helpful to understand.
from react-native-swipeout.
Here you can find out the example : https://www.youtube.com/watch?v=9qof4eCt9UY
from react-native-swipeout.
Related Issues (20)
- Will setNativeProps works for external libraries as well?
- Out of memory error in Swipeout
- Tiny white space between buttons on IOS
- Touchable Opacity Not working after adding swipeout HOT 6
- How to change text dynamically HOT 2
- Calling setState with scroll scrollEnabled argument prevents the swipeoutButtons from opening HOT 1
- stuck problem when swipe
- openLeft/openRight not working HOT 2
- Wrong type exported.
- how to set fontsize HOT 1
- Expo doesn't like react-native-swipeout HOT 1
- Swipe disabled when using TouchableWithoutFeedback HOT 5
- 子条目点击事件和滑动事件怎么解决冲突 HOT 1
- the View in Swipeout can't swipe while swipe it HOT 1
- Swipe Left doesn't push the item it just covers it. HOT 12
- Suggestion to move to @react-native-community HOT 4
- Can I maintain this repository ? HOT 3
- Unsafe Component Warning HOT 2
- How can i change the animation speed of closing/opening animation?
- Is there any prop to autoclose the swipeout when I open another
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from react-native-swipeout.