3.7.87 • Published 3 months ago

@taktikorg/quas-magnam v3.7.87

Weekly downloads
-
License
MIT
Repository
github
Last release
3 months ago

@taktikorg/quas-magnam

996.icu LICENSE

中文文档

Demo

Getting Started

Installation

npm install @taktikorg/quas-magnam --save

Usage

import React from 'react';
import {
  View,
  StyleSheet,
  Text,
} from 'react-native';
import { DraggableGrid } from '@taktikorg/quas-magnam';

interface MyTestProps {

}

interface MyTestState {
  data:{key:string, name:string}[];
}

export class MyTest extends React.Component<MyTestProps, MyTestState>{

  constructor(props:MyTestProps) {
    super(props);
    this.state = {
      data:[
        {name:'1',key:'one'},
        {name:'2',key:'two'},
        {name:'3',key:'three'},
        {name:'4',key:'four'},
        {name:'5',key:'five'},
        {name:'6',key:'six'},
        {name:'7',key:'seven'},
        {name:'8',key:'eight'},
        {name:'9',key:'night'},
        {name:'0',key:'zero'},
      ],
    };
  }

  public render_item(item:{name:string, key:string}) {
    return (
      <View
        style={styles.item}
        key={item.key}
      >
        <Text style={styles.item_text}>{item.name}</Text>
      </View>
    );
  }

  render() {
    return (
      <View style={styles.wrapper}>
        <DraggableGrid
          numColumns={4}
          renderItem={this.render_item}
          data={this.state.data}
          onDragRelease={(data) => {
            this.setState({data});// need reset the props data sort after drag release
          }}
        />
      </View>
    );
  }
}

const styles = StyleSheet.create({
  button:{
    width:150,
    height:100,
    backgroundColor:'blue',
  },
  wrapper:{
    paddingTop:100,
    width:'100%',
    height:'100%',
    justifyContent:'center',
  },
  item:{
    width:100,
    height:100,
    borderRadius:8,
    backgroundColor:'red',
    justifyContent:'center',
    alignItems:'center',
  },
  item_text:{
    fontSize:40,
    color:'#FFFFFF',
  },
});

Props

parametertyperequireddescription
numColumnsnumberyeshow many items should be render on one row
dataarrayyesdata's item must have unique key,item's render will depend on the key
renderItem(item, order:number) => ReactElementyesTakes an item from data and renders it into the list
itemHeightnumbernoif not set this, it will the same as itemWidth
dragStartAnimationobjectnocustom drag start animation
styleobjectnogrid styles

Event Props

parametertyperequireddescription
onItemPress(item) => voidnoFunction will execute when item on press
onDragStart(startDragItem) => voidnoFunction will execute when item start drag
onDragRelease(data) => voidnoFunction will execute when item release, and will return the new ordered data
onResetSort(data) => voidnoFunction will execute when dragged item change sort
onDragging(gestureState: PanResponderGestureState) => voidnoFunction will execute when dragging item
onDragItemActive(item) => voidnoFunction will execute when any item active

Item Props

parametertyperequireddescription
disabledDragbooleannoIt will disable drag for the item
disabledReSortedbooleannoIt will disable resort the item

if you set disabledResorted be true, it will look like that

Custom Drag Start Animation

If you want to use your custom animation, you can do like this

 render() {
    return (
      <View style={styles.wrapper}>
        <DraggableGrid
          numColumns={4}
          renderItem={this.render_item}
          data={this.state.data}
          onDragStart={this.onDragStart}
          dragStartAnimation={{
            transform:[
              {scale:this.state.animatedValue}
            ],
          }}
        />
      </View>
    );
  }

  private onDragStart = () => {
    this.state.animatedValue.setValue(1);
    Animated.timing(this.state.animatedValue, {
      toValue:3,
      duration:400,
    }).start();
  }

Resort item

if you want resort item yourself,you only need change the data's sort, and the draggable-grid will auto resort by your data.

the data's key must unique

3.7.87

3 months ago

3.7.86

3 months ago

3.7.85

3 months ago

3.7.84

4 months ago

3.7.83

4 months ago

3.7.82

4 months ago

3.7.81

4 months ago

3.7.80

4 months ago

3.7.79

4 months ago

3.7.78

4 months ago

3.7.77

4 months ago

3.7.76

4 months ago

3.6.76

4 months ago

3.6.75

4 months ago

3.5.75

4 months ago

3.5.74

4 months ago

3.5.73

4 months ago

3.5.72

4 months ago

3.5.71

4 months ago

3.5.70

4 months ago

3.5.69

4 months ago

3.5.68

4 months ago

3.5.67

4 months ago

3.5.66

4 months ago

3.5.65

4 months ago

3.5.64

4 months ago

3.5.63

4 months ago

3.5.62

4 months ago

3.5.61

4 months ago

3.5.60

4 months ago

3.5.59

4 months ago

2.5.59

4 months ago

2.5.58

4 months ago

2.5.57

5 months ago

2.5.56

5 months ago

2.5.55

5 months ago

2.5.54

5 months ago

2.5.53

5 months ago

2.5.52

5 months ago

2.5.51

5 months ago

2.5.50

5 months ago

2.5.49

5 months ago

2.5.48

5 months ago

2.5.47

5 months ago

2.5.46

5 months ago

2.5.45

5 months ago

2.4.45

5 months ago

2.4.44

5 months ago

2.4.43

5 months ago

2.4.42

5 months ago

2.4.41

5 months ago

2.4.40

5 months ago

2.4.39

5 months ago

2.4.38

5 months ago

2.4.37

5 months ago

1.4.37

5 months ago

1.4.36

5 months ago

1.4.35

5 months ago

1.3.35

5 months ago

1.3.34

5 months ago

1.3.33

5 months ago

1.3.32

5 months ago

1.3.31

5 months ago

1.3.30

6 months ago

1.3.29

6 months ago

1.3.28

6 months ago

1.2.28

6 months ago

1.2.27

6 months ago

1.2.26

6 months ago

1.2.25

6 months ago

1.2.24

6 months ago

1.2.23

6 months ago

1.2.22

6 months ago

1.2.21

6 months ago

1.2.20

6 months ago

1.2.19

6 months ago

1.1.19

6 months ago

1.1.18

6 months ago

1.1.17

6 months ago

1.1.16

6 months ago

1.1.15

6 months ago

1.1.14

6 months ago

1.1.13

6 months ago

1.1.12

6 months ago

1.1.11

6 months ago

1.1.10

6 months ago

1.1.9

6 months ago

1.1.8

6 months ago

1.1.7

6 months ago

1.1.6

6 months ago

1.1.5

6 months ago

1.1.4

6 months ago

1.1.3

6 months ago

1.1.2

7 months ago

1.1.1

7 months ago

1.0.1

7 months ago

1.0.0

7 months ago