Skip to content

Instantly share code, notes, and snippets.

@SharePerson
SharePerson / select2-script
Last active July 21, 2021 13:46
Select2 Ajax Script With List Item UI Formatting
<script type="text/javascript">
$(document).ready(function() {
var pageSize = 20;
$("#UserList").select2({
multiple: true,
width: '100%',
ajax: {
theme: 'bootstrap',
url: "https://gorest.co.in/public/v1/users",
@SharePerson
SharePerson / delete-style.js
Created February 7, 2020 22:55
Delete button styling
deleteButton: {
alignSelf: 'flex-end',
width: 75,
flex: 1,
justifyContent: 'center',
alignItems: 'center',
backgroundColor: 'red',
marginVertical: 3,
}
@SharePerson
SharePerson / render-delete.js
Created February 7, 2020 22:55
Render the delete button
renderHiddenItem(person) {
return (
<TouchableOpacity
style={styles.deleteButton}
onPress={() => this.deletePerson(person.id)}>
<Text style={styles.deleteText}>Delete</Text>
</TouchableOpacity>
);
}
@SharePerson
SharePerson / RNSLV.js
Created February 7, 2020 22:52
using the swipe list view plugin
<SwipeListView
data={this.state.persons}
renderItem={({item}) => this.renderPerson(item)}
renderHiddenItem={({item}) => this.renderHiddenItem(item)}
rightOpenValue={-75}
/>
@SharePerson
SharePerson / delete-person.js
Created February 7, 2020 22:38
Delete person from state immutably
deletePerson(personId) {
let {persons} = this.state;
persons = persons.filter(person => person.id !== personId);
this.setState({...this.state, persons});
}
@SharePerson
SharePerson / right-buttons.js
Created February 7, 2020 22:27
rendering the right buttons
renderRightButtons(personId) {
return [
<View style={styles.deleteContainer}>
<TouchableOpacity
style={styles.deleteButton}
onPress={() => this.deletePerson(personId)}>
<Text style={styles.deleteText}>Delete</Text>
</TouchableOpacity>
</View>,
];
@SharePerson
SharePerson / swipeable.js
Created February 7, 2020 22:23
Rendering swipeable persons
renderPersons() {
if (this.state.persons.length > 0) {
return this.state.persons.map(person => {
return (
<View key={person.id} style={styles.itemContainer}>
<Swipeable
rightButtons={this.renderRightButtons(person.id)}
rightButtonWidth={75}>
<View style={styles.swipeable}>
<Image style={styles.avatar} source={{uri: person.avatarUrl}} />
@SharePerson
SharePerson / api.js
Created February 7, 2020 01:45
Dummy API class
import images from '../data/image-list.json';
import persons from '../data/person-list.json';
export const getImages = () => {
return images;
};
export const getPersons = () => {
return persons;
};
@SharePerson
SharePerson / person-list.json
Last active February 7, 2020 01:44
Person List JSON file
[
{
"id": "1",
"name": "John Smith",
"avatarUrl": "https://randomuser.me/api/portraits/men/75.jpg"
},
{
"id": "2",
"name": "Lance Chapman",
"avatarUrl": "https://randomuser.me/api/portraits/men/41.jpg"
@SharePerson
SharePerson / image-list.json
Last active February 7, 2020 01:44
Image List JSON file
[
{
"id": "1",
"imageUrl": "https://homepages.cae.wisc.edu/~ece533/images/airplane.png"
},
{
"id": "2",
"imageUrl": "https://homepages.cae.wisc.edu/~ece533/images/arctichare.png"
}
]