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(react): Add onClick type definition #4062

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
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
Loading