-
Notifications
You must be signed in to change notification settings - Fork 4k
/
index.native.js
71 lines (65 loc) · 1.77 KB
/
index.native.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
/**
* External dependencies
*/
import { View } from 'react-native';
/**
* WordPress dependencies
*/
import { Caption, RichText } from '@wordpress/block-editor';
import { compose } from '@wordpress/compose';
import { withDispatch, withSelect } from '@wordpress/data';
/**
* Internal dependencies
*/
import styles from './styles.scss';
import { store as blockEditorStore } from '../../store';
const BlockCaption = ( {
accessible,
accessibilityLabelCreator,
onBlur,
onChange,
onFocus,
isSelected,
shouldDisplay,
text,
insertBlocksAfter,
} ) => (
<View style={ [ styles.container, shouldDisplay && styles.padding ] }>
<Caption
accessibilityLabelCreator={ accessibilityLabelCreator }
accessible={ accessible }
isSelected={ isSelected }
onBlur={ onBlur }
onChange={ onChange }
onFocus={ onFocus }
shouldDisplay={ shouldDisplay }
value={ text }
insertBlocksAfter={ insertBlocksAfter }
/>
</View>
);
export default compose( [
withSelect( ( select, { clientId } ) => {
const { getBlockAttributes, getSelectedBlockClientId } = select(
blockEditorStore
);
const { caption } = getBlockAttributes( clientId ) || {};
const isBlockSelected = getSelectedBlockClientId() === clientId;
// We'll render the caption so that the soft keyboard is not forced to close on Android
// but still hide it by setting its display style to none. See wordpress-mobile/gutenberg-mobile#1221
const shouldDisplay =
! RichText.isEmpty( caption ) > 0 || isBlockSelected;
return {
shouldDisplay,
text: caption,
};
} ),
withDispatch( ( dispatch, { clientId } ) => {
const { updateBlockAttributes } = dispatch( blockEditorStore );
return {
onChange: ( caption ) => {
updateBlockAttributes( clientId, { caption } );
},
};
} ),
] )( BlockCaption );