Skip to content

Commit

Permalink
feat(hippy-react): modal visible default true and optional props (#3446)
Browse files Browse the repository at this point in the history
* fix(hippy-react): modal visible default true and optional props

* fix(hippy-react): repeatCount can be 'loop'

* fix(hippy-react): fix ts declaration

* fix(hippy-react): borderStyle can be none

* fix(hippy-react): flex can be number%

* fix(hippy-react-web): flex style declaration

* fix(hippy-react): remove unused virtual

---------

Co-authored-by: OpenHippy <[email protected]>
  • Loading branch information
2 people authored and zealotchen0 committed Aug 28, 2023
1 parent 149fa49 commit 26f04c2
Show file tree
Hide file tree
Showing 12 changed files with 51 additions and 21 deletions.
21 changes: 13 additions & 8 deletions packages/global.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ declare namespace HippyTypes {
height: number | undefined;
}

export type Color = string | number;
export type Color = string;
export type Colors = Color[];
export type tintColor = Color;
export type tintColors = Colors;
Expand Down Expand Up @@ -101,12 +101,11 @@ declare namespace HippyTypes {
| 'space-around';
alignItems?: FlexAlignType;
alignSelf?: 'auto' | FlexAlignType;
aspectRatio?: number | string;
bottom?: DimensionValue;
collapse?: boolean;
collapsable?: boolean;
display?: 'none' | 'flex';
flex?: number;
flex?: DimensionValue;
flexBasis?: DimensionValue;
flexDirection?:
| 'row'
Expand Down Expand Up @@ -191,11 +190,11 @@ declare namespace HippyTypes {
skewY?: string | Animation;
}

// eslint-disable-next-line @typescript-eslint/no-empty-interface
export interface TransformsStyle {
transform?: Transform[];
}

export type BorderStyle = 'solid' | 'dotted' | 'dashed';
export type BorderStyle = 'solid' | 'dotted' | 'dashed' | 'none';
export interface BorderBoxStyle {
borderStyle?: BorderStyle;
borderTopStyle?: BorderStyle;
Expand Down Expand Up @@ -229,7 +228,6 @@ declare namespace HippyTypes {

export interface ViewStyle extends FlexStyle, BoxShadowStyle, BorderBoxStyle, TransformsStyle, BackgroundStyle {
opacity?: DimensionValue;
pointerEvents?: 'box-none' | 'none' | 'box-only' | 'auto';
}

export type TextStyleIOS = ViewStyle;
Expand Down Expand Up @@ -265,7 +263,6 @@ declare namespace HippyTypes {
;
letterSpacing?: number;
lineHeight?: number;
textAlign?: 'auto' | 'left' | 'right' | 'center' | 'justify';
textDecorationLine?:
| 'none'
| 'underline'
Expand Down Expand Up @@ -293,8 +290,14 @@ declare namespace HippyTypes {
export interface Style extends ViewStyle, TextStyle, ImageStyle {
[props: string]: any
}
type Falsy = undefined | null | false;
type RecursiveArray<T> = Array<T | ReadonlyArray<T> | RecursiveArray<T>>;
export type GenericStyleProp<T> =
| T
| RegisteredStyle<T>
| RecursiveArray<T | RegisteredStyle<T> | Falsy>
| Falsy;

type GenericStyleProp<T> = T | T[];
export type StyleProp = GenericStyleProp<Style>;
export type ViewStyleProp = GenericStyleProp<ViewStyle>;
export type ImageStyleProp = GenericStyleProp<ImageStyle>;
Expand Down Expand Up @@ -403,6 +406,8 @@ declare namespace HippyTypes {
height: number;
scale: number;
statusBarHeight: number;
// Android bottom navigatorBar height; supported version is 2.3.4
navigatorBarHeight: number;
width: number;
}

Expand Down
4 changes: 2 additions & 2 deletions packages/hippy-react-web/src/components/list-view.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ import { DEFAULT_DISTANCE_TO_REFRESH, REFRESH_DISTANCE_SCREEN_Y_OFFSET } from '.
import View from './view';

interface ListViewItemProps {
style?: any;
style?: HippyTypes.StyleProp;
height?: any;
children?: any;
type?: any;
Expand Down Expand Up @@ -352,7 +352,7 @@ const ListView: React.FC<ListViewProps> = React.forwardRef((props, ref) => {
}
}, [pullHeaderRef]);
return (
<div ref={pullHeaderRef} style={{ ...styles.pullHeaderContainer }}>
<div ref={pullHeaderRef} style={styles.pullHeaderContainer}>
{renderPullHeader()}
</div>
);
Expand Down
3 changes: 3 additions & 0 deletions packages/hippy-react-web/src/components/modal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ const styles = StyleSheet.create({
width: '100%',
},
container: {
// @ts-ignore
position: 'fixed',
top: 0,
right: 0,
Expand Down Expand Up @@ -64,10 +65,12 @@ const styles = StyleSheet.create({
animationName: 'fadeout',
},
slideIn: {
// @ts-ignore
transform: 'translateY(0%)',
animationName: 'slidein',
},
slideOut: {
// @ts-ignore
transform: 'translateY(100%)',
animationName: 'slideout',
},
Expand Down
6 changes: 5 additions & 1 deletion packages/hippy-react-web/src/modules/stylesheet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@

// @ts-nocheck
import { Device } from '../native';
export interface StyleObj {
[key: string]: HippyTypes.Style | HippyTypes.ViewStyle | HippyTypes.ImageStyle | HippyTypes.TextStyle;
}


const ratio = Device.screen.scale;
let onePixel = Math.round(0.4 * ratio) / ratio;
Expand All @@ -28,7 +32,7 @@ if (onePixel === 0) {
}

const StyleSheet = {
create: styleObj => styleObj,
create: (styleObj: StyleObj): StyleObj => styleObj,
hairlineWidth: onePixel,
compose: (style: any, style2: Record<string, any>) => {
let cloneStyle = {};
Expand Down
4 changes: 2 additions & 2 deletions packages/hippy-react/src/components/modal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@ export interface ModalProps {
/**
* Show or hide
*
* Default false
* Default true
*/
visible: boolean;
visible?: boolean;

/**
* Primary key
Expand Down
2 changes: 1 addition & 1 deletion packages/hippy-react/src/components/text-input.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ export interface TextInputProps extends LayoutableProps, ClickableProps {
/**
* The string that will be rendered before text input has been entered.
*/
placeholder?: number;
placeholder?: string;

/**
* The text color of the placeholder string.
Expand Down
4 changes: 2 additions & 2 deletions packages/hippy-react/src/components/text.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ export interface TextProps extends LayoutableProps, ClickableProps {
* The default is `tail`.
*/
ellipsizeMode?: 'head' | 'middle' | 'tail' | 'clip';
children: number | string | string[];
children: number | string | string[] | React.ReactNode;
text?: string;
style?: HippyTypes.TextStyleProp;

Expand All @@ -76,7 +76,7 @@ export interface TextProps extends LayoutableProps, ClickableProps {
function forwardRef(
{ style, forbidUnicodeToChar, ...nativeProps }: TextProps,
// eslint-disable-next-line max-len
ref: string | ((instance: HTMLParagraphElement | null) => void) | React.RefObject<HTMLParagraphElement> | null | undefined,
ref: string | React.ReactNode | ((instance: HTMLParagraphElement | null) => void) | React.RefObject<HTMLParagraphElement> | null | undefined,
) {
const nativeStyle = style;

Expand Down
4 changes: 3 additions & 1 deletion packages/hippy-react/src/components/view.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ export class View extends React.Component<ViewProps, {}> {
}

public render() {
const { collapsable, style = {}, ...nativeProps } = this.props;
const { collapsable, style = {}, onFocus, ...nativeProps } = this.props;
let nativeStyle: HippyTypes.StyleProp = style;
const { nativeBackgroundAndroid } = nativeProps;
if (typeof collapsable === 'boolean') {
Expand All @@ -116,6 +116,8 @@ export class View extends React.Component<ViewProps, {}> {
nativeName="View"
// @ts-ignore
style={nativeStyle}
// @ts-ignore
onFocus={onFocus}
{...nativeProps}
/>
);
Expand Down
3 changes: 1 addition & 2 deletions packages/hippy-react/src/modules/animation-set.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,7 @@ interface AnimationChild {

interface AnimationSetOption {
children: AnimationChild[];
repeatCount: number;
virtual: any; // TODO: What's it?
repeatCount: number | 'loop';
}

interface AnimationSet extends Animation {
Expand Down
4 changes: 2 additions & 2 deletions packages/hippy-react/src/modules/animation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ interface AnimationOptions {
/**
* Animation repeat times, use 'loop' to be always repeating.
*/
repeatCount?: number;
repeatCount?: number | 'loop';

inputRange?: any[];
outputRange?: any[];
Expand Down Expand Up @@ -277,7 +277,7 @@ class Animation implements Animation {
*
* @param {Object} newConfig - new animation schema
*/
public updateAnimation(newConfig: AnimationOptions) {
public updateAnimation(newConfig: Partial<AnimationOptions>) {
if (typeof newConfig !== 'object') {
throw new TypeError('Invalid arguments');
}
Expand Down
15 changes: 15 additions & 0 deletions packages/hippy-react/src/types/global.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,18 @@ declare global {
interface Global extends HippyTypes.HippyGlobal {};
}
};

declare namespace HippyTypes {
export interface FlexStyle {
aspectRatio?: number | string;
}
export interface ViewStyle extends FlexStyle, BoxShadowStyle, BorderBoxStyle, TransformsStyle, BackgroundStyle {
pointerEvents?: 'box-none' | 'none' | 'box-only' | 'auto';
}
export interface TransformsStyle {
transform?: Transform[];
}
export interface TextStyle {
textAlign?: 'auto' | 'left' | 'right' | 'center' | 'justify';
}
}
2 changes: 2 additions & 0 deletions packages/hippy-react/src/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,8 @@ export interface LayoutableProps {
* @param {number} evt.layout.height - The height of component
*/
onLayout?: (evt: LayoutEvent) => void;
onAttachedToWindow?: () => void;
onDetachedFromWindow?: () => void;
}

export interface ClickableProps {
Expand Down

0 comments on commit 26f04c2

Please sign in to comment.