Skip to content

Commit

Permalink
feat(react): Add onClick type definition
Browse files Browse the repository at this point in the history
  • Loading branch information
jimmyjzli committed Oct 12, 2024
1 parent 09092a2 commit b524b7f
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 9 deletions.
12 changes: 12 additions & 0 deletions driver/js/packages/global.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,12 @@
declare namespace HippyTypes {

export type __PLATFORM__ = 'ios' | 'android' | null;
export interface Event {
type: string;
bubbles: boolean;
currentTarget: Element | null;
target: Element | null;
}

export interface TouchEvent {
// Touch coordinate X
Expand All @@ -31,6 +37,12 @@ declare namespace HippyTypes {
page_y: number;
}


export interface ClickEvent extends Event {
eventPhase: EventPhase;
[key: string]: any;
}

export interface FocusEvent {
// Focus status
focus: boolean;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ interface FocusableProps {
nextFocusUpId?: string;
nextFocusLeftId?: string;
nextFocusRightId?: string;
onClick?: () => void;
onClick?: (evt: HippyTypes.ClickEvent) => void;
onFocus?: (evt: HippyTypes.FocusEvent) => void;
}

Expand Down
13 changes: 6 additions & 7 deletions driver/js/packages/hippy-react/src/event/event.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,13 @@
* limitations under the License.
*/

interface Event {
type: string;
bubbles: boolean;
currentTarget: Element | null;
target: Element | null;
}

class Event implements Event {
class Event implements HippyTypes.Event {
public type: string;
public bubbles: boolean;
public currentTarget: Element | null;
public target: Element | null;

/**
* constructor
* @param eventName - handler name, e.g. onClick
Expand Down
2 changes: 1 addition & 1 deletion driver/js/packages/hippy-react/src/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ export interface ClickableProps {
/**
* Called when the touch is released.
*/
onClick?: () => void;
onClick?: (evt: HippyTypes.ClickEvent) => void;

/**
* Called when the touch with longer than about 1s is released.
Expand Down

0 comments on commit b524b7f

Please sign in to comment.