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

Feat/incubator.toast optional icon #2263

Closed
wants to merge 3 commits into from
Closed
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
@@ -1,11 +1,6 @@
import React from 'react';

console.log('keyboard is not supported on web');
const CustomKeyboardView = () => {

return (
null
);
return null;
};

export default CustomKeyboardView;
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
import React from 'react';

console.log('KeyboardTrackingView not supported on web');
const KeyboardTrackingView = () => {
return (null
);
return null;
};

export default KeyboardTrackingView;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,7 @@ export default class KeyboardAwareListView extends KeyboardAwareBase {

constructor(props) {
super(props);
LogService.warn(
'RNUILib: Please stop Using KeyboardAwareListView, use either KeyboardAwareScrollView or KeyboardAwareFlatList'
);
LogService.warn('RNUILib: Please stop Using KeyboardAwareListView, use either KeyboardAwareScrollView or KeyboardAwareFlatList');
}

render() {
Expand Down
6 changes: 2 additions & 4 deletions src/components/carousel/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -239,10 +239,8 @@ class Carousel extends Component<CarouselProps, CarouselState> {
if (containerWidth) {
const spacings = pageWidth === containerWidth ? 0 : this.getItemSpacings(this.props);
const initialBreak = pageWidth - (containerWidth - pageWidth - spacings) / 2;
const snapToOffsets = _.times(
presenter.getChildrenLength(this.props),
index => initialBreak + index * pageWidth + this.getContainerMarginHorizontal()
);
const snapToOffsets = _.times(presenter.getChildrenLength(this.props),
index => initialBreak + index * pageWidth + this.getContainerMarginHorizontal());
return snapToOffsets;
}
};
Expand Down
6 changes: 2 additions & 4 deletions src/components/chipsInput/Presenter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,9 @@ export const getCounterText = (count: number, maxLength: number) => {
return `${Math.min(count, maxLength)} / ${maxLength}`;
};

export const getChipDismissColor = (
chip: ChipsInputChipProps,
export const getChipDismissColor = (chip: ChipsInputChipProps,
isSelected: boolean,
defaultChipProps?: ChipsInputChipProps
) => {
defaultChipProps?: ChipsInputChipProps) => {
const dismissColor = defaultChipProps?.dismissColor || Colors.white;
return !chip.invalid ? dismissColor : isSelected ? Colors.red10 : Colors.red30;
};
Expand Down
7 changes: 2 additions & 5 deletions src/components/featureHighlight/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -223,8 +223,7 @@ class FeatureHighlight extends Component<FeatureHighlightProps, State> {
toValue, // Animate to value
duration: toValue ? 100 : 0, // Make it take a while
useNativeDriver: true
}
).start(); // Starts the animation
}).start(); // Starts the animation
}

setTargetPosition(props = this.props) {
Expand Down Expand Up @@ -260,9 +259,7 @@ class FeatureHighlight extends Component<FeatureHighlightProps, State> {
topPosition = isUnderMin ? topPosition + innerPadding : targetCenter + minRectHeight / 2 + innerPadding / 2;
}
if (topPosition < 0 || topPosition + this.contentHeight > Constants.screenHeight) {
console.warn(
`Content is too long and might appear off screen. Please adjust the message length for better results.`
);
console.warn(`Content is too long and might appear off screen. Please adjust the message length for better results.`);
}
return topPosition;
}
Expand Down
6 changes: 2 additions & 4 deletions src/components/pageControl/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -114,14 +114,12 @@ class PageControl extends PureComponent<PageControlProps, State> {

if (Array.isArray(props.size)) {
if (props.size[0] >= props.size[1] || props.size[1] >= props.size[2]) {
console.warn(
'It is recommended that largeSize > mediumSize > smallSize, currently: smallSize=',
console.warn('It is recommended that largeSize > mediumSize > smallSize, currently: smallSize=',
props.size[0],
'mediumSize=',
props.size[1],
'largeSize=',
props.size[2]
);
props.size[2]);
}
}
}
Expand Down
6 changes: 2 additions & 4 deletions src/components/panningViews/panListenerView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -134,13 +134,11 @@ class PanListenerView extends PureComponent<Props> {
const {dy, dx} = gestureState;
const {directions, panSensitivity = DEFAULT_PAN_SENSITIVITY} = this.props;

return Boolean(
directions &&
return Boolean(directions &&
((directions.includes(PanningProvider.Directions.UP) && dy < -panSensitivity) ||
(directions.includes(PanningProvider.Directions.DOWN) && dy > panSensitivity) ||
(directions.includes(PanningProvider.Directions.LEFT) && dx < -panSensitivity) ||
(directions.includes(PanningProvider.Directions.RIGHT) && dx > panSensitivity))
);
(directions.includes(PanningProvider.Directions.RIGHT) && dx > panSensitivity)));
};

handlePanStart = () => {
Expand Down
84 changes: 37 additions & 47 deletions src/incubator/TextField/withFieldState.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,9 @@ export interface FieldStateProps extends TextInputProps {
validate?: Validator | Validator[];
}

function withFieldState(
WrappedComponent: React.ComponentType<
function withFieldState(WrappedComponent: React.ComponentType<
FieldStateInjectedProps & TextInputProps
>
) {
>) {
const WithFieldState = ({
validate,
validateOnBlur,
Expand All @@ -53,52 +51,44 @@ function withFieldState(
}
}, []);

const validateField = useCallback(
(valueToValidate = value) => {
let _isValid = true;
if (_.isFunction(validate)) {
_isValid = validate(valueToValidate);
} else if (_.isString(validate)) {
_isValid = validators[validate]?.(valueToValidate);
}

setIsValid(_isValid);
},
[value]
);

const onFocus = useCallback(
(...args: any) => {
setIsFocused(true);
//@ts-expect-error
props.onFocus?.(...args);
},
[props.onFocus]
);
const validateField = useCallback((valueToValidate = value) => {
let _isValid = true;
if (_.isFunction(validate)) {
_isValid = validate(valueToValidate);
} else if (_.isString(validate)) {
_isValid = validators[validate]?.(valueToValidate);
}

const onBlur = useCallback(
(...args: any) => {
setIsFocused(false);
//@ts-expect-error
props.onBlur?.(...args);
if (validateOnBlur) {
validateField();
}
},
[props.onBlur, validateOnBlur, validateField]
);
setIsValid(_isValid);
},
[value]);

const onFocus = useCallback((...args: any) => {
setIsFocused(true);
//@ts-expect-error
props.onFocus?.(...args);
},
[props.onFocus]);

const onBlur = useCallback((...args: any) => {
setIsFocused(false);
//@ts-expect-error
props.onBlur?.(...args);
if (validateOnBlur) {
validateField();
}
},
[props.onBlur, validateOnBlur, validateField]);

const onChangeText = useCallback(
(text: string) => {
setValue(text);
props.onChangeText?.(text);
const onChangeText = useCallback((text: string) => {
setValue(text);
props.onChangeText?.(text);

if (validateOnChange) {
validateField(text);
}
},
[props.onChangeText, validateOnChange]
);
if (validateOnChange) {
validateField(text);
}
},
[props.onChangeText, validateOnChange]);

const fieldState = useMemo(() => {
return {value, hasValue: !_.isEmpty(value), isValid, isFocused};
Expand Down
13 changes: 12 additions & 1 deletion src/incubator/toast/index.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
import React, {PropsWithChildren, useCallback, useEffect, useMemo, useRef, useState} from 'react';
import {ActivityIndicator, StyleSheet, findNodeHandle, AccessibilityInfo, ViewStyle, LayoutChangeEvent} from 'react-native';
import {
ActivityIndicator,
StyleSheet,
findNodeHandle,
AccessibilityInfo,
ViewStyle,
LayoutChangeEvent
} from 'react-native';
import _ from 'lodash';
import {Constants, asBaseComponent} from '../../commons/new';
import {useDidUpdate} from '../../hooks';
Expand Down Expand Up @@ -169,6 +176,10 @@ const Toast = (props: PropsWithChildren<ToastProps>) => {
};

const renderIcon = () => {
if (!icon) {
return null;
}

return (
<Icon source={toastPreset.icon} resizeMode={'contain'} style={styles.icon} tintColor={toastPreset.iconColor}/>
);
Expand Down