mirror of
https://github.com/zoriya/react-native-web.git
synced 2026-06-04 19:05:49 +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 Image from '../';
|
||||||
import ImageUriCache from '../ImageUriCache';
|
import ImageUriCache from '../ImageUriCache';
|
||||||
import React from 'react';
|
import React from 'react';
|
||||||
import { mount, render } from 'enzyme';
|
import { mount, render, shallow } from 'enzyme';
|
||||||
|
|
||||||
const originalCanUseDOM = ExecutionEnvironment.canUseDOM;
|
const originalCanUseDOM = ExecutionEnvironment.canUseDOM;
|
||||||
const originalImage = window.Image;
|
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"', () => {
|
describe('prop "resizeMode"', () => {
|
||||||
[
|
[
|
||||||
Image.resizeMode.contain,
|
Image.resizeMode.contain,
|
||||||
|
|||||||
@@ -79,6 +79,7 @@ class Image extends Component {
|
|||||||
...ViewPropTypes,
|
...ViewPropTypes,
|
||||||
children: any,
|
children: any,
|
||||||
defaultSource: ImageSourcePropType,
|
defaultSource: ImageSourcePropType,
|
||||||
|
draggable: bool,
|
||||||
onError: func,
|
onError: func,
|
||||||
onLayout: func,
|
onLayout: func,
|
||||||
onLoad: func,
|
onLoad: func,
|
||||||
@@ -155,6 +156,7 @@ class Image extends Component {
|
|||||||
accessible,
|
accessible,
|
||||||
children,
|
children,
|
||||||
defaultSource,
|
defaultSource,
|
||||||
|
draggable,
|
||||||
onLayout,
|
onLayout,
|
||||||
source,
|
source,
|
||||||
testID,
|
testID,
|
||||||
@@ -188,6 +190,7 @@ class Image extends Component {
|
|||||||
// Allows users to trigger the browser's image context menu
|
// Allows users to trigger the browser's image context menu
|
||||||
const hiddenImage = displayImage
|
const hiddenImage = displayImage
|
||||||
? createDOMElement('img', {
|
? createDOMElement('img', {
|
||||||
|
draggable,
|
||||||
src: displayImage,
|
src: displayImage,
|
||||||
style: [StyleSheet.absoluteFill, styles.img]
|
style: [StyleSheet.absoluteFill, styles.img]
|
||||||
})
|
})
|
||||||
|
|||||||
Reference in New Issue
Block a user