Giter VIP home page Giter VIP logo

swipeout's Introduction

rc-swipeout


iOS-style swipeout buttons that appear from behind a component (web & react-native support)

NPM version build status Test coverage

Screenshots

rc-swipeout

Installation

npm install --save rc-swipeout

Development

web:
npm install
npm start

rn:
tnpm run rn-start

Example

react-native

./node_modules/rc-tools run react-native-init
react-native run-ios

Usage

import Swipeout from 'rc-swipeout';
import 'rc-swipeout/assets/index.less'; (web only)

<Swipeout
  left={[
    {
      text: 'reply',
      onPress:() => console.log('reply'),
      style: { backgroundColor: 'orange', color: 'white' },
      className: 'custom-class-1'
    }
  ]}
  right={[
    {
      text: 'delete',
      onPress:() => console.log('delete'),
      style: { backgroundColor: 'red', color: 'white' },
      className: 'custom-class-2'
    }
  ]}
  onOpen={() => console.log('open')}
  onClose={() => console.log('close')}
>
  <div style={{height: 44}}> swipeout demo </div>
</Swipeout>

API

props

name description type default
prefixCls className prefix String rc-swipeout
style swipeout style Object ``
left swipeout buttons on left Array []
right swipeout buttons on right Array []
autoClose auto close on button press Boolean function() {}
onOpen Function function() {}
onClose Function function() {}
disabled disabled swipeout Boolean false

button props

name description type default
text button text String Click
style button style Object ``
onPress button press function Function function() {}
className button custom class String ``

Test Case

npm test
npm run chrome-test

Coverage

npm run coverage

open coverage/ dir

License

rc-swipeout is released under the MIT license.

swipeout's People

Contributors

cht8687 avatar fearintino avatar jamesnocentini avatar kylewang4929 avatar martyan avatar paranoidjk avatar quentinyang avatar silentcloud avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

swipeout's Issues

Swipeout buttons are already visible without swiping

Hi,

I am trying to use this library however the swipeout actions seem to already be visible before swiping.

This is how I added the Swipeout component to my page:

subprojects.map((sp, i) => {
    const progressPercentage = sp.progress * 100;
    
    return (
        <Swipeout
            right={[
                {
                    text: 'Alles NVT',
                    onPress: () => console.log('nvt'),
                },
                {
                    text: 'Alles OK',
                    onPress: () => console.log('ok')
                }
            ]}>
            <div key={sp.id} className='project-list-item custom-checkbox-wrapper' onClick={this.goToSubproject(sp.id)}>
                <span className='project-list-count'>{i + 1}</span>
                <p>{sp.description}</p>
                <p>{sp.surface} m2 &nbsp;&nbsp;|&nbsp;&nbsp; {sp.constructionYear}</p>
                <div className='project-list-timeline'>
                    <span className='bar' style={{ width: `${progressPercentage}%` }}></span>
                </div>
                <div className='custom-checkbox'>
                    <input type="checkbox" id='1' disabled checked={sp.progress === 1} />
                    <label htmlFor='1'>
                        <span></span>
                    </label>
                </div>
            </div>    
        </Swipeout>                                            
    );
})

However, when I do it like this both of the actions are already unconvered before swiping:
Actions swiped

I have covered the actions in a green rectangle. How come they are already visible before swiping to the left? Did I miss a setting?

I'm working with React 15.6, Swipeout 2.0.4

Need event for onPress

I need to be able to stopPropagation when onPress is called. Currently there is no event passed in so there is no way to cancel it.

Can button have icon?

Would be nice to have icons on left or right buttons.

Would be even better to pass JSX.Element

Fix the readme.md

In readme.md file in demo code in props "right" you have to write {[ instead of [{.

dist build is broken?

Hi there,

I am trying to use the dist build of the swipeout component, but it seems like the build is broken!

Here's a minimal example in a codepen:

https://codepen.io/sherbondy/pen/jzKKrz?editors=1111

As you can see, both React and ReactDOM are available on the global window object, but the swipeout dist script is assigning an empty JavaScript object to window["rc-swipeout"].

Any idea what might be amiss?

I tried forking the repository and fiddling with the config in the package.json file.

I initially thought it might be a quirk with an older webpack version, so I tried bumping the rc-tools dependency to v7, but no go!

I also experimented with changing the config.output.libraryTarget setting, e.g. to be window instead of umd, but that causes the library to throw an error on import:

Uncaught TypeError: Cannot read property 'Component' of undefined

I'm a little out of my depth here, so if anyone has any pointers or ideas, re: what might be messing up the dist build, I would love to hear your advice!

Also, just an ergonomic thing, I think it'd be nicer if the config.output.library setting was changed to, e.g. Swipeout so you could call window.Swipeout instead of using the more awkward window["rc-swipeout"] syntax (due to the dash in the name).

Thanks!

Left swipe isn't working

On Left Swipe the content is displays but the card is not behavioral as similar to Right Swipe.
Capture-error

how to prevent event bind to this component's children when I just want to close the swipe?

When the swipe is opened (such as the right buttons is visible), then I tap the list item intend to close it. But now, the event which is bound on the child be fired.
Before:
<Swipeout right={[ { text: '删除', onPress: () => this.handleDelete(), style: { backgroundColor: '#fc352b', color: 'white' }, }, ]} onClose={() => { console.log('close!'); }} ><div onClick={()=>{browserHistory.push('/pageTwo');}}>Go to page two</div> </Swipeout>

While I has an idea is that bind another event to the component, only when the swipe is closed can be fired.

Modified:
(1)file:Swipeout.out.js
Swipeout.prototype.onTap = function onTap() { if (this.openedLeft || this.openedRight) { this.close(); }else{ this.props.onPress(); } };
(2)
<Swipeout right={[ { text: '删除', onPress: () => this.handleDelete(), style: { backgroundColor: '#fc352b', color: 'white' }, }, ]} onClose={() => { console.log('close!'); }} onPress={()=>{browserHistory.push('/pageTwo');}} ><div>Go to page two</div> </Swipeout>

Would you give some suggestions?

How can i get the info whether it is swipeRight or swipeLeft?

I want to know the swipe direction, and for different direction i want to add other css.
Now i can only use the methods onClose and onOpen. It can trigger the onClose and onOpen, but i can not tell the onOpen is triggered by swipeRight or swipeLeft.

doOpenRight 方法传参问题

swipeout/src/Swipeout.tsx

Lines 146 to 148 in 8e6d1e7

doOpenRight = () => {
this.open(-this.btnsRightWidth, true, false);
}

上面这段代码中的 this.open 方法的第 2、3 个参数是不是反了,虽然最终未影响到代码逻辑,但正确的是不是应该是下面这样的?

doOpenRight = () => { 
   this.open(-this.btnsRightWidth, false, true); 
 } 

Auto close swipeout buttons on lost focus

I add swipeout component to ListItem of ListView, I want swipeout will close the swipeout buttons when this ListItem lost focus (close when scrolling the ListView or choose other item of ListView).

Thanks
Quan Vo

the buttons total width unequal the parent's width

I have two right buttons : one width is '50px' another '70px' ; i think the parent container(<div class="rc-swipeout-actions rc-swipeout-actions-right"></div>) should be '120px' . unfortunately is still '150px'.
finally i find the reason that my screen width is '375px' ,the parent container has a limit width: 375/5 * 2
(buttons count) = 150, so the width not depend on the children's total width but the screen‘s width and buttons count .......

Warning: componentWillMount has been renamed, and is not recommended for use

Expo Version ~41.0.0
"react": "16.13.1"
"rc-swipeout": "^2.0.11",

When I use Swipeout component, I get this warning in console

Warning: componentWillMount has been renamed, and is not recommended for use. See https://fb.me/react-unsafe-component-lifecycles for details.

  • Move code with side effects to componentDidMount, and set initial state in the constructor.
  • Rename componentWillMount to UNSAFE_componentWillMount to suppress this warning in non-strict mode. In React 17.x, only the UNSAFE_ name will work. To rename all deprecated lifecycles to their new names, you can run npx react-codemod rename-unsafe-lifecycles in your project source folder.

Please update the following components: %s, Swipeout

Warning: componentWillReceiveProps has been renamed, and is not recommended for use. See https://fb.me/react-unsafe-component-lifecycles for details.

  • Move data fetching code or side effects to componentDidUpdate.
  • If you're updating state whenever props change, refactor your code to use memoization techniques or move it to static getDerivedStateFromProps. Learn more at: https://fb.me/react-derived-state
  • Rename componentWillReceiveProps to UNSAFE_componentWillReceiveProps to suppress this warning in non-strict mode. In React 17.x, only the UNSAFE_ name will work. To rename all deprecated lifecycles to their new names, you can run npx react-codemod rename-unsafe-lifecycles in your project source folder.

Please update the following components: %s, Swipeout

Missing custom component support

In src/Swipeout.tsx:

  renderCustomButton(button) {
    const buttonStyle = button.style || {};
    const bgColor = buttonStyle.backgroundColor || 'transparent';
    const Component = (
      <View
        style={{
          flex: 1, justifyContent: 'center', alignItems: 'center', backgroundColor: bgColor,
        }}
      >
        {React.isValidElement(button.text) ? button.text : (
          <Text style={[button.style, { textAlign: 'center' }]}>
            {button.text}
          </Text>
        )}
      </View>
    );
    return {
      text: button.text || 'Click',
      onPress: button.onPress,
      type: 'default',
      component: Component,
      backgroundColor: 'transparent',
      color: '#999',
      disabled: false,
    };
  }

button.component is simply ignored but the parameter exists in react-native-swiperout, please add the parameter so we can use custom component like custom icon in swipeout.

Move import css to package

Could You move import css file inside the package ?

Then user can only import whole component and don't worry about import css in own *.js file.

Buggy right swipe [Android]

Problem:

While the swipe from left to right is really smooth and in terms of timing/swing, if I swipe to the opposite direction I get no smooth transition at all. The two buttons at the right appear all of a sudden and eventually they disappear in the same fashion.
I've used the same code of this example

Gif:

My stack:

  • mobile: Nexus 5x emulator (API 23)
  • react-native-cli: 2.0.1
  • react-native: 0.38.0

onCloseSwipe 方法

在 onCloseSwipe 方法中
if (node.className.indexOf('rc-swipeout-actions') > -1) {
这行代码中的 'rc-swipeout-actions' 应该是 this.props.prefixCls+‘-actions’ 吧?!

Can't figure out how to close?

Component slides open just fine, but then I can't get it to close without clicking a button. Clicking the button closes if I have autoClose flag set, but how can I swipe back to close?

BTW Absolutely love this component, it's so simple & the animation is so smooth! Great work!

Swipe width not recalculated after left or right buttons change

If the property left (or right) changes his value, the width of the swipe movement doesn't get recalculated.

If for example the left property contains 2 buttons, the width is calculated in the componentDidMount method with an initial value. After a change in the left property it has now 4 button, but the swipe width is still the initial one (when it should be much more). The result is that the two new buttons are only partially visible or not visible al all.
The same happens with the right property.
I only verified this problem in the browser, not in native version of the Swipeout component.

To solve this problem simply add a componentDidUpdate like this:

componentDidUpdate() {
    this.btnsLeftWidth = this.left ? this.left.offsetWidth : 0;
    this.btnsRightWidth = this.right ? this.right.offsetWidth : 0;
}

Thanks

点击svg标签时报错

if (node.className.indexOf(`${this.props.prefixCls}-actions`) > -1) {

Uncaught TypeError: node.className.indexOf is not a function

当打开一条以上的情况下,并且开启了autoClose,当列表中有svg标签时,点击svg标签会导致错误

Does not work with TextInput

I'm using it to wrap a TextInput and the TextInputs are not clickable/usable anymore. Can you see into the issue?

Swipeout right={
[{
text: 'ok'
}]
}>

<TextInput /

The TextInput is no longer useable

Wrong dimensionsof this.btnsLeftWidth when ComponentDidMount

I noticed that in some cases this function in Swipeout.js:

 _createClass(Swipeout, [{
        key: 'componentDidMount',
        value: function componentDidMount() {
            this.btnsLeftWidth = this.left ? this.left.offsetWidth : 0;
            this.btnsRightWidth = this.right ? this.right.offsetWidth : 0;
            document.body.addEventListener('touchstart', this.onCloseSwipe, true);
        }
    },

returns me this.btnsLeftWidth as 0 because this.left.offsetWidth returns 0 even though this.left is defined and it's a proper

It happens when I have fixed dialog and the content of it as
image

As a result this.btnsLeftWidth is 0 and this block (that responsible for swiping)

var limit = value > 0 ? _this.btnsLeftWidth : -_this.btnsRightWidth;
            var contentLeft = _this._getContentEasing(value, limit);
            var transform = 'translate3d(' + contentLeft + 'px, 0px, 0px)'; 

return translate3d(0px,0px,0px) which does not swipe.

Quick fix was to add setTimeout on that function (even with 0 delay it fixes the issue).

_createClass(Swipeout, [
    {
      key: 'componentDidMount',
      value: function componentDidMount() {
        setTimeout(() => {
          this.btnsLeftWidth = this.left ? this.left.offsetWidth : 0
          this.btnsRightWidth = this.right ? this.right.offsetWidth : 0
          document.body.addEventListener('touchstart', this.onCloseSwipe, true)
        }, 0)
      }
    },

Could you please have a look and maybe find something better?

[Resolved] Chrome warning 'Unable to preventDefault inside passive event listener'

Chrome56 touchstart 事件默认是被动事件(passive), 不能调用 preventDefault。详见 Scrolling Intervention

大体上有两条路可选:

  1. document.body.addEventListener('touchstart', this.onCloseSwipe.bind(this), {passive: false}); 但并不是所有浏览器都支持 EventListenerOptions
  2. 官方建议是用 touch-action CSS 属性来控制元素对 touch 事件的响应。

我查了半天竟然没有找到一个变量来指示 preventDefault 是否可以调用。Modernizr 给出的测试代码是 try catch。

Unable to preventDefault inside passive event listener due to target being treated as passive.
See https://www.chromestatus.com/features/5093566007214080
onCloseSwipe @ Swipeout.web.js?5589b3f:97

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.