mirror of
https://github.com/zoriya/react-native-web.git
synced 2026-05-25 15:42:24 +00:00
[add] Image: draggable prop
Allows control over browser's default drag-and-drop behaviour for images. Setting draggable to 'false' will prevent dragging. Close #514
This commit is contained in:
@@ -4,7 +4,7 @@ import ExecutionEnvironment from 'fbjs/lib/ExecutionEnvironment';
|
||||
import Image from '../';
|
||||
import ImageUriCache from '../ImageUriCache';
|
||||
import React from 'react';
|
||||
import { mount, render } from 'enzyme';
|
||||
import { mount, render, shallow } from 'enzyme';
|
||||
|
||||
const originalCanUseDOM = ExecutionEnvironment.canUseDOM;
|
||||
const originalImage = window.Image;
|
||||
@@ -76,6 +76,14 @@ describe('components/Image', () => {
|
||||
});
|
||||
});
|
||||
|
||||
test('prop "draggable"', () => {
|
||||
const defaultSource = { uri: 'https://google.com/favicon.ico' };
|
||||
const component = shallow(<Image defaultSource={defaultSource} />);
|
||||
expect(component.find('img').prop('draggable')).toBeUndefined();
|
||||
component.setProps({ defaultSource, draggable: false });
|
||||
expect(component.find('img').prop('draggable')).toBe(false);
|
||||
});
|
||||
|
||||
describe('prop "resizeMode"', () => {
|
||||
[
|
||||
Image.resizeMode.contain,
|
||||
|
||||
@@ -79,6 +79,7 @@ class Image extends Component {
|
||||
...ViewPropTypes,
|
||||
children: any,
|
||||
defaultSource: ImageSourcePropType,
|
||||
draggable: bool,
|
||||
onError: func,
|
||||
onLayout: func,
|
||||
onLoad: func,
|
||||
@@ -155,6 +156,7 @@ class Image extends Component {
|
||||
accessible,
|
||||
children,
|
||||
defaultSource,
|
||||
draggable,
|
||||
onLayout,
|
||||
source,
|
||||
testID,
|
||||
@@ -188,6 +190,7 @@ class Image extends Component {
|
||||
// Allows users to trigger the browser's image context menu
|
||||
const hiddenImage = displayImage
|
||||
? createDOMElement('img', {
|
||||
draggable,
|
||||
src: displayImage,
|
||||
style: [StyleSheet.absoluteFill, styles.img]
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user