Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[RNMobile] Add Cover Block media settings #25810

Merged
merged 124 commits into from
Feb 15, 2021
Merged
Show file tree
Hide file tree
Changes from 119 commits
Commits
Show all changes
124 commits
Select commit Hold shift + click to select a range
cd1befa
Render media within settings panel
dcalhoun Jan 12, 2021
44fdbff
Display media edit button
dcalhoun Jan 12, 2021
e4860fb
Add "Edit focal point" bottom sheet cell
dcalhoun Jan 12, 2021
75f9d1e
Replace unused bottom cell value
dcalhoun Jan 12, 2021
0477dbd
Enable navigation to edit focal point sheet
dcalhoun Jan 12, 2021
b606bdb
[wip] Add focal point settings component
dcalhoun Jan 12, 2021
d424c62
[wip] Add native focal point picker
dcalhoun Jan 12, 2021
8d1e097
Create foundation for focal point picker UI
dcalhoun Jan 12, 2021
51252ab
Remove duplicative effect
dcalhoun Jan 12, 2021
f487970
Add focal point picker media and range controls
dcalhoun Jan 12, 2021
671f5f0
Remove unnecessary minHeight prop
dcalhoun Jan 12, 2021
c8111a0
Add focal point picker handle
dcalhoun Jan 12, 2021
c6f3fdc
Position focal point handle based upon state
dcalhoun Jan 12, 2021
44a559a
[wip] Add drag handler for focal point picker
dcalhoun Jan 12, 2021
3dc61d2
Fix lint warning
dcalhoun Jan 12, 2021
8f3540c
Update focal point picker blue
dcalhoun Jan 12, 2021
db2e923
Fix bad merge conflict resolution
dcalhoun Jan 12, 2021
d255312
Fix various lint warnings
dcalhoun Jan 12, 2021
2c13764
Add TODO note
dcalhoun Jan 12, 2021
c179755
Change default position for focal point range cells
dcalhoun Jan 12, 2021
7e7d1a1
Add TapGestureHandler to focal point picker
dcalhoun Jan 12, 2021
049a64d
Round value for RangeControl text input
dcalhoun Jan 12, 2021
c1fa9ef
Add focal point hint to Cover Block media preview
dcalhoun Jan 12, 2021
af5b6f4
Simplify RangeControl props
dcalhoun Jan 12, 2021
e41ef7e
Clear focal point when clearing media
dcalhoun Jan 12, 2021
3e2232a
Add Fixed background toggle
dcalhoun Jan 12, 2021
2c18ac0
Display button to attach media when no media is attached
dcalhoun Jan 12, 2021
9a60273
Fix beginning drag atop focal point picker drag handle
dcalhoun Jan 12, 2021
b7f7c2c
Render media preview within fixed dimensions
dcalhoun Jan 12, 2021
3560843
Leverage full-height sub-sheet for focal point picker
dcalhoun Jan 12, 2021
694093e
Sync pan gesture values to sliders
dcalhoun Jan 12, 2021
bb57730
Display percentage suffix for sliders
dcalhoun Jan 12, 2021
ea469ce
Improve focal point picker styles
dcalhoun Jan 12, 2021
9aef3c4
Reduce max-height for media preview
dcalhoun Jan 12, 2021
3b69a0e
Limit max-height for focal point picker media
dcalhoun Jan 12, 2021
88b1694
Replace RNGH with RN PanResponder to fix Android modals
dcalhoun Jan 12, 2021
cf27fb3
Improve PanResponder implementation
dcalhoun Jan 12, 2021
325dcf5
Abstract FocalPoint into separate file
dcalhoun Jan 12, 2021
865a227
Revert "Leverage full-height sub-sheet for focal point picker"
dcalhoun Jan 12, 2021
b0c0794
Add drag handle tooltip
dcalhoun Jan 12, 2021
013a37c
Hoist tooltip visibility control into focal point picker
dcalhoun Jan 12, 2021
b869cd1
Prevent collapsed placeholder element while image size is fetched
dcalhoun Jan 12, 2021
c3e5135
Revert "Revert "Leverage full-height sub-sheet for focal point picker""
dcalhoun Jan 12, 2021
4662e8d
Fix odd layout jumping when incrementing slider key
dcalhoun Jan 12, 2021
4ed9c22
Revert "Revert "Revert "Leverage full-height sub-sheet for focal poin…
dcalhoun Jan 12, 2021
d582298
Limit fixed background setting to images
dcalhoun Jan 12, 2021
e42d31a
Duplicate styles needed for focal point settings
dcalhoun Jan 12, 2021
978159e
Add dynamic focal point to media preview
dcalhoun Jan 12, 2021
c5cb3ef
Ensure focal point coordinates are never empty
dcalhoun Jan 12, 2021
987b833
Disable focal point hint for fixed background media
dcalhoun Jan 12, 2021
080775e
Render media preview for videos
dcalhoun Jan 12, 2021
dbace3c
Fix video media preview sizing
dcalhoun Jan 12, 2021
f707b70
Improve video media preview sizing
dcalhoun Jan 12, 2021
b279aef
Add video support to focal point picker
dcalhoun Jan 12, 2021
231a8f0
Simplify prop type logic
dcalhoun Jan 12, 2021
86c90e2
Address review feedback
dcalhoun Jan 12, 2021
6bd7027
Refactor Tooltip to dismiss on tap
dcalhoun Jan 12, 2021
9650d0c
Add focal point picker tooltip flag
dcalhoun Jan 12, 2021
86ac0e4
Improve placeholder media to prevent layout jumps
dcalhoun Jan 12, 2021
624c52e
Tooltip overlay avoids blocking child context interactivity
dcalhoun Jan 12, 2021
e53fab7
Improve tooltip styles
dcalhoun Jan 12, 2021
f5bbc3c
Add guard for undefined prop callback
dcalhoun Jan 12, 2021
b6305f8
Fix focal point picker drag handle jump
dcalhoun Jan 12, 2021
8638aba
Support left aligned tooltips
dcalhoun Jan 12, 2021
22d6aa7
Page template picker shares tooltip
dcalhoun Jan 12, 2021
5de1ef5
Expand Tooltip positioning flexibility
dcalhoun Jan 12, 2021
dc7a918
Support right aligned tooltips
dcalhoun Jan 12, 2021
2bfd4ef
Tapping tooltip label dismisses tooltip
dcalhoun Jan 12, 2021
9055e8a
Update focal point picker tooltip usage
dcalhoun Jan 12, 2021
b0ec062
Fix disallowed syntax throwing lint errors
dcalhoun Jan 12, 2021
5874f0b
Abstract Cover controls to reduce file size
dcalhoun Jan 12, 2021
c084ef9
Fix lint warning
dcalhoun Jan 12, 2021
cf87563
Replace potential circular dependency with type check utility
dcalhoun Jan 12, 2021
283c3c2
Fix erroneously flush media preview
dcalhoun Jan 12, 2021
21d6a47
Prevent focal point hint overlapping edit media button
dcalhoun Jan 12, 2021
5d937a8
Replace HoC with Hook
dcalhoun Jan 12, 2021
30e46a3
Revert "Update focal point picker tooltip usage"
dcalhoun Jan 12, 2021
633763d
Revert "Page template picker shares tooltip"
dcalhoun Jan 12, 2021
50e0431
Leverage UnitControl for focal point picker
dcalhoun Jan 12, 2021
1f46e3f
Avoid scrolling focal point picker with full-height bottom sheet
dcalhoun Jan 12, 2021
b796bd9
Remove unnecessary bottom sheet methods
dcalhoun Jan 12, 2021
1853077
Ensure full-height bottom sheet does not linger
dcalhoun Jan 12, 2021
e2dd07b
Fix bad merge conflict resolution
dcalhoun Jan 12, 2021
6f9832d
Remove lingering, unused code
dcalhoun Jan 12, 2021
6a1186e
Fix negative and lost values when dragging outside bounds
dcalhoun Jan 13, 2021
7234e4b
Add comments for additional context
dcalhoun Jan 13, 2021
05ff592
Avoid unnecessary re-renders with useCallback
dcalhoun Jan 13, 2021
4f4c326
Display tooltip within demo editor
dcalhoun Jan 15, 2021
341ed71
Remove unnecessary useCallback usage
dcalhoun Jan 19, 2021
f111b29
Avoid importing react directly
dcalhoun Jan 19, 2021
c786cc8
Remove short-sighted fix for full-height bottom sheet
dcalhoun Jan 19, 2021
e8fa55c
Remove unused import
dcalhoun Jan 19, 2021
b7ea9ec
Fix broken min-height increment
dcalhoun Jan 20, 2021
8164451
Remove erroneously committed configuration file
dcalhoun Jan 21, 2021
dd50dbd
Mobile - Wip - Picker and BottomSheet
Jan 25, 2021
9a59885
Add MediaUpload within bottom sheet context
dcalhoun Jan 27, 2021
70b2fcc
Compute relative coordinates in PanResponder release
dcalhoun Jan 27, 2021
571a928
Capture Podfile.lock changes
dcalhoun Jan 27, 2021
b4aaf9f
Capture Podfile.lock changes
dcalhoun Jan 27, 2021
72a2fc8
Revert "Capture Podfile.lock changes"
dcalhoun Jan 29, 2021
533347f
Apply consistent media background
dcalhoun Feb 2, 2021
50d5c10
Remove highlight border from focal point media
dcalhoun Feb 2, 2021
a24d4f7
Disable focal point picker when fixed background enabled
dcalhoun Feb 2, 2021
a92d752
Remove extra padding atop and beneath focal point picker settings
dcalhoun Feb 2, 2021
bf1b3f8
Update focal point hint styles
dcalhoun Feb 2, 2021
fa0522a
Use two digit strings for coordinates
dcalhoun Feb 3, 2021
5888a5f
Fix style lint error
dcalhoun Feb 3, 2021
b55359a
Reduce opacity of disabled focal point navigation button
dcalhoun Feb 3, 2021
da89b6f
Remove bottom margin beneath media preview
dcalhoun Feb 4, 2021
28b5b92
Allow focal point cross-hair to overflow horizontal bounds
dcalhoun Feb 9, 2021
46d079b
Allow long press action for bottom cell
dcalhoun Feb 5, 2021
c848e78
Add edit image accessibility label
dcalhoun Feb 5, 2021
b07e0bc
Improve accessibility of edit image button
dcalhoun Feb 5, 2021
9ac6f70
Reorder Cover block media settings sections
dcalhoun Feb 10, 2021
967f587
Add clear media button to inspector controls Cover image edit button
dcalhoun Feb 10, 2021
6b1c160
Improve double modal handling for iOS
dcalhoun Feb 10, 2021
0aa90e5
Merge branch 'master' of github.com:dcalhoun/gutenberg into rnmobile/…
dcalhoun Feb 10, 2021
ec34cee
Increase a11y label accuracy
dcalhoun Feb 10, 2021
e96e1d4
Improve accessibility of add media button
dcalhoun Feb 10, 2021
0a7f72c
Pass string through a11n tooling
dcalhoun Feb 11, 2021
20841c6
Improve focal point settings media styles
dcalhoun Feb 12, 2021
84cec15
Avoid invisible, paused videos on Android
dcalhoun Feb 12, 2021
44edcd8
Prevent image from overflowing width
dcalhoun Feb 12, 2021
81ee23c
Add CHANGELOG note
dcalhoun Feb 15, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { InspectorControls } from '@wordpress/block-editor';
import {
BottomSheet,
ColorSettings,
FocalPointSettings,
LinkPickerScreen,
} from '@wordpress/components';
import { compose } from '@wordpress/compose';
Expand All @@ -18,6 +19,7 @@ import { store as blockEditorStore } from '../../store';
export const blockSettingsScreens = {
settings: 'Settings',
color: 'Color',
focalPoint: 'FocalPoint',
linkPicker: 'linkPicker',
};

Expand Down Expand Up @@ -47,6 +49,12 @@ function BottomSheetSettings( {
>
<ColorSettings defaultSettings={ settings } />
</BottomSheet.NavigationScreen>
<BottomSheet.NavigationScreen
name={ blockSettingsScreens.focalPoint }
fullScreen
>
<FocalPointSettings />
</BottomSheet.NavigationScreen>
<BottomSheet.NavigationScreen
name={ blockSettingsScreens.linkPicker }
fullScreen
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ export class MediaUpload extends Component {
( option ) => {
return {
...option,
requiresModal: true,
types: allowedTypes,
id: option.value,
};
Expand All @@ -60,6 +61,7 @@ export class MediaUpload extends Component {
id: mediaSources.deviceCamera, // ID is the value sent to native
value: mediaSources.deviceCamera + '-IMAGE', // This is needed to diferenciate image-camera from video-camera sources.
label: __( 'Take a Photo' ),
requiresModal: true,
types: [ MEDIA_TYPE_IMAGE ],
icon: capturePhoto,
};
Expand All @@ -68,6 +70,7 @@ export class MediaUpload extends Component {
id: mediaSources.deviceCamera,
value: mediaSources.deviceCamera,
label: __( 'Take a Video' ),
requiresModal: true,
types: [ MEDIA_TYPE_VIDEO ],
icon: captureVideo,
};
Expand All @@ -76,6 +79,7 @@ export class MediaUpload extends Component {
id: mediaSources.deviceLibrary,
value: mediaSources.deviceLibrary,
label: __( 'Choose from device' ),
requiresModal: true,
types: [ MEDIA_TYPE_IMAGE, MEDIA_TYPE_VIDEO ],
icon: image,
};
Expand All @@ -84,6 +88,7 @@ export class MediaUpload extends Component {
id: mediaSources.siteMediaLibrary,
value: mediaSources.siteMediaLibrary,
label: __( 'WordPress Media Library' ),
requiresModal: true,
types: [
MEDIA_TYPE_IMAGE,
MEDIA_TYPE_VIDEO,
Expand Down
294 changes: 294 additions & 0 deletions packages/block-library/src/cover/controls.native.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,294 @@
/**
* External dependencies
*/
import { View } from 'react-native';
import Video from 'react-native-video';

/**
* WordPress dependencies
*/
import {
Image,
Icon,
IMAGE_DEFAULT_FOCAL_POINT,
PanelBody,
RangeControl,
UnitControl,
TextControl,
BottomSheet,
ToggleControl,
} from '@wordpress/components';
import { plus } from '@wordpress/icons';
import { useState, useCallback } from '@wordpress/element';
import { usePreferredColorSchemeStyle } from '@wordpress/compose';
import { InspectorControls, MediaUpload } from '@wordpress/block-editor';
import { __ } from '@wordpress/i18n';

/**
* Internal dependencies
*/
import styles from './style.scss';
import OverlayColorSettings from './overlay-color-settings';
import FocalPointSettings from './focal-point-settings';
import {
ALLOWED_MEDIA_TYPES,
COVER_MIN_HEIGHT,
COVER_MAX_HEIGHT,
COVER_DEFAULT_HEIGHT,
CSS_UNITS,
IMAGE_BACKGROUND_TYPE,
VIDEO_BACKGROUND_TYPE,
} from './shared';

function Controls( {
attributes,
didUploadFail,
hasOnlyColorBackground,
isUploadInProgress,
onClearMedia,
onSelectMedia,
setAttributes,
} ) {
const {
backgroundType,
dimRatio,
hasParallax,
focalPoint,
minHeight,
minHeightUnit = 'px',
url,
} = attributes;
const CONTAINER_HEIGHT = minHeight || COVER_DEFAULT_HEIGHT;
const onHeightChange = useCallback(
( value ) => {
if ( minHeight || value !== COVER_DEFAULT_HEIGHT ) {
setAttributes( { minHeight: value } );
}
},
[ minHeight ]
);

const onOpacityChange = useCallback( ( value ) => {
setAttributes( { dimRatio: value } );
}, [] );

const onChangeUnit = useCallback( ( nextUnit ) => {
setAttributes( {
minHeightUnit: nextUnit,
minHeight:
nextUnit === 'px'
? Math.max( CONTAINER_HEIGHT, COVER_MIN_HEIGHT )
: CONTAINER_HEIGHT,
} );
}, [] );

const [ displayPlaceholder, setDisplayPlaceholder ] = useState( true );

function setFocalPoint( value ) {
setAttributes( { focalPoint: value } );
}

const toggleParallax = () => {
setAttributes( {
hasParallax: ! hasParallax,
...( ! hasParallax
? { focalPoint: undefined }
: { focalPoint: IMAGE_DEFAULT_FOCAL_POINT } ),
} );
};

const addMediaButtonStyle = usePreferredColorSchemeStyle(
styles.addMediaButton,
styles.addMediaButtonDark
);

function focalPointPosition( { x, y } = IMAGE_DEFAULT_FOCAL_POINT ) {
return {
left: `${ ( hasParallax ? 0.5 : x ) * 100 }%`,
top: `${ ( hasParallax ? 0.5 : y ) * 100 }%`,
};
}

const [ videoNaturalSize, setVideoNaturalSize ] = useState( null );

const mediaBackground = usePreferredColorSchemeStyle(
styles.mediaBackground,
styles.mediaBackgroundDark
);
const imagePreviewStyles = [
displayPlaceholder && styles.imagePlaceholder,
];
const videoPreviewStyles = [
{
aspectRatio:
videoNaturalSize &&
videoNaturalSize.width / videoNaturalSize.height,
height: '100%',
},
! displayPlaceholder && styles.video,
displayPlaceholder && styles.imagePlaceholder,
];

const focalPointHint = ! hasParallax && ! displayPlaceholder && (
<Icon
icon={ plus }
size={ styles.focalPointHint.width }
style={ [
styles.focalPointHint,
focalPointPosition( focalPoint ),
] }
/>
);

const renderMediaSection = ( {
open: openMediaOptions,
getMediaOptions,
} ) => (
<>
{ getMediaOptions() }
{ url ? (
<>
<BottomSheet.Cell
accessible={ false }
cellContainerStyle={ [
styles.mediaPreview,
mediaBackground,
] }
onLongPress={ openMediaOptions }
>
<View style={ styles.mediaInner }>
{ IMAGE_BACKGROUND_TYPE === backgroundType && (
<Image
editButton={ ! displayPlaceholder }
highlightSelected={ false }
isSelected={ ! displayPlaceholder }
isUploadFailed={ didUploadFail }
isUploadInProgress={ isUploadInProgress }
mediaPickerOptions={ [
{
destructiveButton: true,
id: 'clearMedia',
label: __( 'Clear Media' ),
onPress: onClearMedia,
separated: true,
value: 'clearMedia',
},
] }
onImageDataLoad={ () => {
setDisplayPlaceholder( false );
} }
onSelectMediaUploadOption={ onSelectMedia }
openMediaOptions={ openMediaOptions }
url={ url }
height="100%"
style={ imagePreviewStyles }
width={ styles.image.width }
/>
) }
{ VIDEO_BACKGROUND_TYPE === backgroundType && (
<Video
muted
paused
disableFocus
onLoad={ ( event ) => {
const {
height,
width,
} = event.naturalSize;
setVideoNaturalSize( {
height,
width,
} );
setDisplayPlaceholder( false );
} }
resizeMode={ 'cover' }
source={ { uri: url } }
style={ videoPreviewStyles }
/>
) }
{ displayPlaceholder ? null : focalPointHint }
</View>
</BottomSheet.Cell>
<FocalPointSettings
disabled={ hasParallax }
focalPoint={ focalPoint || IMAGE_DEFAULT_FOCAL_POINT }
onFocalPointChange={ setFocalPoint }
url={ url }
/>
{ IMAGE_BACKGROUND_TYPE === backgroundType && (
<ToggleControl
label={ __( 'Fixed background' ) }
checked={ hasParallax }
onChange={ toggleParallax }
/>
) }
<TextControl
leftAlign
label={ __( 'Clear Media' ) }
labelStyle={ styles.clearMediaButton }
onPress={ onClearMedia }
/>
</>
) : (
<TextControl
label={ __( 'Add image or video' ) }
labelStyle={ addMediaButtonStyle }
leftAlign
onPress={ openMediaOptions }
/>
) }
</>
);

return (
<InspectorControls>
<PanelBody title={ __( 'Media' ) }>
<MediaUpload
allowedTypes={ ALLOWED_MEDIA_TYPES }
isReplacingMedia={ ! hasOnlyColorBackground }
onSelect={ onSelectMedia }
render={ renderMediaSection }
/>
</PanelBody>

<OverlayColorSettings
overlayColor={ attributes.overlayColor }
customOverlayColor={ attributes.customOverlayColor }
gradient={ attributes.gradient }
customGradient={ attributes.customGradient }
setAttributes={ setAttributes }
/>

{ url ? (
<PanelBody>
<RangeControl
label={ __( 'Opacity' ) }
minimumValue={ 0 }
maximumValue={ 100 }
value={ dimRatio }
onChange={ onOpacityChange }
style={ styles.rangeCellContainer }
separatorType={ 'topFullWidth' }
/>
</PanelBody>
) : null }

<PanelBody title={ __( 'Dimensions' ) }>
<UnitControl
label={ __( 'Minimum height' ) }
min={ minHeightUnit === 'px' ? COVER_MIN_HEIGHT : 1 }
max={ COVER_MAX_HEIGHT }
unit={ minHeightUnit }
value={ CONTAINER_HEIGHT }
onChange={ onHeightChange }
onUnitChange={ onChangeUnit }
units={ CSS_UNITS }
style={ styles.rangeCellContainer }
key={ minHeightUnit }
/>
</PanelBody>
</InspectorControls>
);
}

export default Controls;
Loading