-
Notifications
You must be signed in to change notification settings - Fork 4.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[RNMobile] Extract caption component (#16825)
* Extract caption component * Use caption component for video * Move Caption to block-editor for mobile tests This move avoids a dependency issue that was causing the mobile tests to fail due to the Caption component's import of RichText from the block-editor package. * Pass onBlur to Caption component * Connect Caption component to store
- Loading branch information
Showing
5 changed files
with
114 additions
and
66 deletions.
There are no files selected for viewing
65 changes: 65 additions & 0 deletions
65
packages/block-editor/src/components/caption/index.native.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
/** | ||
* External dependencies | ||
*/ | ||
import { View } from 'react-native'; | ||
|
||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { RichText } from '@wordpress/block-editor'; | ||
import { compose } from '@wordpress/compose'; | ||
import { withDispatch, withSelect } from '@wordpress/data'; | ||
import { __ } from '@wordpress/i18n'; | ||
|
||
const Caption = ( { accessible, accessibilityLabel, onBlur, onChange, onFocus, isSelected, shouldDisplay, text } ) => ( | ||
<View style={ { padding: 12, flex: 1, display: shouldDisplay ? 'flex' : 'none' } } | ||
accessible={ accessible } | ||
accessibilityLabel={ accessibilityLabel } | ||
accessibilityRole={ 'button' } | ||
> | ||
<RichText | ||
rootTagsToEliminate={ [ 'p' ] } | ||
placeholder={ __( 'Write caption…' ) } | ||
value={ text } | ||
onChange={ onChange } | ||
unstableOnFocus={ onFocus } | ||
onBlur={ onBlur } // always assign onBlur as props | ||
isSelected={ isSelected } | ||
__unstableMobileNoFocusOnMount | ||
fontSize={ 14 } | ||
underlineColorAndroid="transparent" | ||
textAlign={ 'center' } | ||
tagName={ '' } | ||
/> | ||
</View> | ||
); | ||
|
||
export default compose( [ | ||
withSelect( ( select, { accessibilityLabelCreator, clientId } ) => { | ||
const { | ||
getBlockAttributes, | ||
getSelectedBlockClientId, | ||
} = select( 'core/block-editor' ); | ||
const { caption } = getBlockAttributes( clientId ); | ||
const accessibilityLabel = accessibilityLabelCreator ? accessibilityLabelCreator( caption ) : undefined; | ||
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 { | ||
accessibilityLabel, | ||
shouldDisplay, | ||
text: caption, | ||
}; | ||
} ), | ||
withDispatch( ( dispatch, { clientId } ) => { | ||
const { updateBlockAttributes } = dispatch( 'core/block-editor' ); | ||
return { | ||
onChange: ( caption ) => { | ||
updateBlockAttributes( clientId, { caption } ); | ||
}, | ||
}; | ||
} ), | ||
] )( Caption ); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters