{"size": 1742, "ext": "js", "max_stars_repo_path": "src/keys.js", "max_stars_repo_name": "SatsumaLabs/react-native-typed-navigation", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/keys.js", "max_issues_repo_name": "SatsumaLabs/react-native-typed-navigation", "max_issues_repo_issues_event_min_datetime": "2019-02-05T09:37:45.000Z", "max_issues_repo_issues_event_max_datetime": "2019-02-06T06:31:46.000Z", "max_forks_repo_path": "src/keys.js", "max_forks_repo_name": "SatsumaLabs/react-native-typed-navigation", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": null, "max_issues_count": 1, "max_forks_count": null, "avg_line_length": 37.0638297872, "max_line_length": 145, "alphanum_fraction": 0.7129735936}
// @flow

import type {ComponentType, ElementConfig} from 'react';
import {Navigation} from 'react-native-navigation';

export opaque type ComponentClassKey<-Props> = string;

export opaque type ComponentId = string;
export opaque type StaticComponentId : ComponentId = ComponentId;
export function makeStaticComponentId(tag: string): StaticComponentId {return tag;}

var registerComponentCtr : number = 0;

export function registerComponent<Props, ScreenType: ComponentType<Props>>(screen: ScreenType):
        ComponentClassKey<$ReadOnly<$Diff<ElementConfig<ScreenType>,{componentId: ComponentId | void}>>> {
    const dname = screen.displayName || screen.name || "";
    registerComponentCtr++;
    const tag = "NavScreen-" + registerComponentCtr + "-" + dname;
    Navigation.registerComponent(tag, () => screen);
    return tag;
}

// An opaque wrapper is required here as Flow does not support this kind of existential type
// the correct type is forall p. {+name: : ComponentClassKey<p>, +passProps: p}
export opaque type ComponentIntent : {+name: ComponentClassKey<empty>, +passProps: mixed} = {+name: ComponentClassKey<empty>, +passProps: mixed};

export function Intent<Props: {}, Opt>(target: ComponentClassKey<Props>, props: Props, opts?: Opt):
        {|+ component: ComponentIntent & {+options?: Opt} |} {
    return {component: {
        name: target,
        passProps: props,
        options: opts
    }};
}

export opaque type ButtonId = string;
var buttonKeyCounter : number = 0;

export function ButtonKey(name?: string): ButtonId {
    buttonKeyCounter++;
    const tag = "btn-" + buttonKeyCounter + "-" + (name || "");
    return tag;
}

export type ExternalComponentKey = string;
export type SharedElementKey = string;
