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

[Mobile] - Prevent passing potential false values to the onPress prop #60595

Merged
merged 5 commits into from
Apr 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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 @@ -9,6 +9,7 @@ import { View } from 'react-native';
import { withPreferredColorScheme } from '@wordpress/compose';
import { Button } from '@wordpress/components';
import { Icon, plusCircleFilled } from '@wordpress/icons';
import { useCallback } from '@wordpress/element';

/**
* Internal dependencies
Expand All @@ -23,6 +24,20 @@ function ButtonBlockAppender( {
isFloating = false,
onAddBlock,
} ) {
const onAppenderPress = useCallback(
( onToggle ) => () => {
if ( onAddBlock ) {
onAddBlock();
return;
}

if ( onToggle ) {
onToggle();
}
},
[ onAddBlock ]
);

const appenderStyle = {
...styles.appender,
...getStylesFromColorScheme(
Expand All @@ -44,7 +59,7 @@ function ButtonBlockAppender( {
renderToggle={ ( { onToggle, disabled, isOpen } ) => (
<Button
testID="appender-button"
onClick={ onAddBlock || onToggle }
onClick={ onAppenderPress( onToggle ) }
aria-expanded={ isOpen }
disabled={ disabled }
fixedRatio={ false }
Expand Down
8 changes: 7 additions & 1 deletion packages/block-library/src/cover/edit.native.js
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,12 @@ const Cover = ( {
closeSettingsBottomSheet();
}, [ closeSettingsBottomSheet ] );

const onAddMediaButtonPress = useCallback( () => {
if ( openMediaOptionsRef?.current ) {
openMediaOptionsRef.current();
}
}, [] );

function setColor( color ) {
const colorValue = getColorObjectByColorValue( colorsDefault, color );

Expand Down Expand Up @@ -352,7 +358,7 @@ const Cover = ( {
accessibilityHint={ accessibilityHint }
accessibilityLabel={ __( 'Add image or video' ) }
accessibilityRole="button"
onPress={ openMediaOptionsRef.current }
onPress={ onAddMediaButtonPress }
>
<View style={ styles.selectImageContainer }>
<View style={ styles.selectImage }>
Expand Down
1 change: 1 addition & 0 deletions packages/react-native-editor/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ For each user feature we should also add a importance categorization label to i
## Unreleased
- [*] Add empty fallback option for the BottomSheetSelectControl component [#60333]
- [*] Fix Quote Block styles [#60476]
- [*] Prevent passing potential false values to the onPress prop [#60595]

## 1.116.0
- [**] Highlight color formatting style improvements [#57650]
Expand Down
Loading