1.1.10 • Published 4 days ago

@juigorg/blanditiis-libero-quos v1.1.10

Weekly downloads
-
License
MIT
Repository
github
Last release
4 days ago

@juigorg/blanditiis-libero-quos

996.icu LICENSE

中文文档

Demo

Getting Started

Installation

npm install @juigorg/blanditiis-libero-quos --save

Usage

import React from 'react';
import {
  View,
  StyleSheet,
  Text,
} from 'react-native';
import { DraggableGrid } from '@juigorg/blanditiis-libero-quos';

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

utilitiesfolderwaitsyntaxexecuteworkspace:*appstyled-componentsRxJSserializerhelperECMAScript 6Uint8ArrayInt32Arraybinariesvarsurlstslibprivate datastyleguidesharedreadlazyECMAScript 5east-asian-widthgenericssesfindLastcensorjasmineindicatorruntimeoutputnegative zerogetoptwrapelectroncolumnvalidatepyyamlpromisesshrinkwrapconsoleiterationsearchguidjsxdebuggerroutingstringsource mapmime-dbobjecttypesyupeventEmitterArray.prototype.flathardlinkscolorsawaitkinesisMicrosoftES2023bytejestPushwhichstructuredClonefigletreact-testing-libraryefficientjapanese[[Prototype]]argumentprivatetapbundlingglobalObject.keyseslintfast-clonerm -rfproxyfullES2021link$.extendincludesjsdomes-abstractPromisewordbreakarttypeerrorduplexredactdirmrulocationthreesuperstructcontainsbusyBigUint64Arrayfindupparse256wgettypescriptcollection.es6schemaieidletypedlocalshimjsstreamajvObject.valuesdeepclonetyped arrayFunction.prototype.namestyleslimitstylees8reactserializetoolkititeratecmdstartObject.entriesJSON-SchemavpcsetRegExp#flagslockfilesafeprettyfind-upflatMapdeepcopy-0form-validationphoneqsbyteLengthkeyexecdayjsWebSocketsgraphqlasttypesafeECMAScript 2023ECMAScript 3react animationpicomatchmonorepoUint8ClampedArraylook-uppropertiesloadingoptionglobalshascirculargdprcolumnseverysymbolimportexportObject.getPrototypeOfflatshellpersistentcallbindcharacterstylingutilObjectarktypeboundinstallerelbsequencechaiawsCSSStyleDeclarationfetchfastcopyopeneropensenvironmentschromiumsortstable_.extendidentifiersnativehasOwnPropertyfiltertrimEndenderrapidemitfast-copySetArray.prototype.flatMapawesomesauceRxmergeconcurrency.envcliamazonES2017stdlibchannelcss-in-jsfunctionsameValueZeroiteratorassertiontddbufferses2017autoprefixerArray.prototype.flattenregular expressionreal-timeuuidforkreduxparentbrowserjsdiffpromisejshintexeclass-validatoryamltc39lintupecmascriptxtermcolorquerystringnodejscompilerposecallboundArrayendpointES8arraybuffercurlassignfast-deep-clonehas-owntextprogressaccessorinternalRegExp.prototype.flags
1.1.10

4 days ago

1.1.9

5 days ago

1.1.8

6 days ago

1.0.8

7 days ago

1.0.7

8 days ago

1.0.6

9 days ago

1.0.5

10 days ago

1.0.4

11 days ago

1.0.3

12 days ago

1.0.2

13 days ago

1.0.1

14 days ago

1.0.0

14 days ago