/** * Interfaces.ts * * Copyright (c) Microsoft Corporation. All rights reserved. * Licensed under the MIT license. * * Defines the template for the ReactXP interface that needs to be * implemented for each platform. */ import * as React from 'react'; import SubscribableEvent from 'subscribableevent'; import AppConfig from './AppConfig'; import * as Types from './Types'; export { Types }; export abstract class ActivityIndicator extends React.Component {} export abstract class Alert { abstract show(title: string, message?: string, buttons?: Types.AlertButtonSpec[], options?: Types.AlertOptions): void; } export abstract class AnimatedComponent

, T, C> extends React.Component { abstract setNativeProps(props: P): void; } export abstract class AnimatedImage extends AnimatedComponent { } export abstract class AnimatedText extends AnimatedComponent { } export abstract class AnimatedTextInput extends AnimatedComponent { } export abstract class AnimatedView extends AnimatedComponent implements FocusableComponent { abstract setFocusRestricted(restricted: boolean): void; abstract setFocusLimited(limited: boolean): void; abstract focus(): void; abstract requestFocus(): void; abstract blur(): void; } export abstract class App { supportsExperimentalKeyboardNavigation = false; // Initialization initialize(debug: boolean, development: boolean): void { AppConfig.setAppConfig(debug, development); } // Activation State abstract getActivationState(): Types.AppActivationState; activationStateChangedEvent = new SubscribableEvent<(state: Types.AppActivationState) => void>(); // Memory Warnings memoryWarningEvent = new SubscribableEvent<() => void>(); } export abstract class UserInterface { abstract setMainView(element: React.ReactElement): void; abstract registerRootView(viewKey: string, getComponentFunc: Function): void; abstract useCustomScrollbars(enable?: boolean): void; // Screen Information abstract isHighPixelDensityScreen(): boolean; abstract getPixelRatio(): number; // Measurements abstract measureLayoutRelativeToWindow(component: React.Component): Promise; abstract measureLayoutRelativeToAncestor(component: React.Component, ancestor: React.Component): Promise; abstract measureWindow(rootViewId?: string): Types.Dimensions; // Content Size Multiplier abstract getContentSizeMultiplier(): Promise; contentSizeMultiplierChangedEvent = new SubscribableEvent<(multiplier: number) => void>(); // On-screen Keyboard abstract dismissKeyboard(): void; // Latency Warnings abstract enableTouchLatencyEvents(latencyThresholdMs: number): void; touchLatencyEvent = new SubscribableEvent<(observedLatencyMs: number) => void>(); // Keyboard navigation abstract isNavigatingWithKeyboard(): boolean; keyboardNavigationEvent = new SubscribableEvent<(isNavigatingWithKeyboard: boolean) => void>(); } export abstract class Modal { abstract isDisplayed(modalId?: string): boolean; abstract show(modal: React.ReactElement, modalId: string, options?: Types.ModalOptions): void; abstract dismiss(modalId: string): void; abstract dismissAll(): void; } export abstract class Popup { abstract show(options: Types.PopupOptions, popupId: string, delay?: number): boolean; abstract autoDismiss(popupId: string, delay?: number): void; abstract dismiss(popupId: string): void; abstract dismissAll(): void; abstract isDisplayed(popupId?: string): boolean; } export abstract class Linking { // Incoming deep links abstract getInitialUrl(): Promise; deepLinkRequestEvent = new SubscribableEvent<(url: string) => void>(); // Outgoing deep links abstract openUrl(url: string): Promise; abstract launchSms(smsData: Types.SmsInfo): Promise; abstract launchEmail(emailData: Types.EmailInfo): Promise; protected abstract _createEmailUrl(emailInfo: Types.EmailInfo): string; } export abstract class Accessibility { abstract isScreenReaderEnabled(): boolean; abstract isHighContrastEnabled(): boolean; abstract announceForAccessibility(announcement: string): void; screenReaderChangedEvent = new SubscribableEvent<(isEnabled: boolean) => void>(); highContrastChangedEvent = new SubscribableEvent<(isEnabled: boolean) => void>(); } export interface FocusableComponent { focus(): void; requestFocus(): void; blur(): void; } export abstract class Button extends React.Component implements FocusableComponent { abstract focus(): void; abstract requestFocus(): void; abstract blur(): void; } export abstract class Picker extends React.Component {} export class Component extends React.Component {} export interface ImageConstructor { new (props: Types.ImageProps): Image; prefetch(url: string): Promise; getMetadata(url: string): Promise; } export abstract class Image extends React.Component { abstract getNativeWidth(): number | undefined; abstract getNativeHeight(): number | undefined; } export abstract class Clipboard { abstract setText(text: string): void; abstract getText(): Promise; } export abstract class Link extends React.Component implements FocusableComponent { abstract focus(): void; abstract requestFocus(): void; abstract blur(): void; } export abstract class Storage { abstract getItem(key: string): Promise; abstract setItem(key: string, value: string): Promise; abstract removeItem(key: string): Promise; abstract clear(): Promise; } export abstract class Location { abstract isAvailable(): boolean; abstract setConfiguration(config: LocationConfiguration): void; abstract getCurrentPosition(options?: PositionOptions): Promise; abstract watchPosition(successCallback: Types.LocationSuccessCallback, errorCallback?: Types.LocationFailureCallback, options?: PositionOptions): Promise; abstract clearWatch(watchID: Types.LocationWatchId): void; } export interface LocationConfiguration { // if true, assumes permission is already granted skipPermissionRequests: boolean; } export abstract class Platform { abstract getType(): Types.PlatformType; abstract select(specifics: { [ platform in Types.PlatformType | 'default' ]?: T }): T | undefined; } export abstract class Input { backButtonEvent = new SubscribableEvent<() => boolean>(true); keyDownEvent = new SubscribableEvent<(e: Types.KeyboardEvent) => boolean>(true); keyUpEvent = new SubscribableEvent<(e: Types.KeyboardEvent) => boolean>(true); } export interface ScrollViewConstructor { new(props: Types.ScrollViewProps): ScrollView; } export interface ScrollView extends React.Component { setScrollTop(scrollTop: number, animate?: boolean): void; setScrollLeft(scrollLeft: number, animate?: boolean): void; } export abstract class StatusBar { abstract isOverlay(): boolean; abstract setHidden(hidden: boolean, showHideTransition: 'fade' | 'slide'): void; abstract setBarStyle(style: 'default' | 'light-content' | 'dark-content', animated: boolean): void; abstract setNetworkActivityIndicatorVisible(value: boolean): void; abstract setBackgroundColor(color: string, animated: boolean): void; abstract setTranslucent(translucent: boolean): void; } export abstract class Styles { abstract combine(ruleSet1: Types.StyleRuleSetRecursive | undefined, ruleSet2?: Types.StyleRuleSetRecursive) : Types.StyleRuleSetOrArray | undefined; abstract createViewStyle(ruleSet: Types.ViewStyle, cacheStyle?: boolean): Types.ViewStyleRuleSet; abstract createAnimatedViewStyle(ruleSet: Types.AnimatedViewStyle): Types.AnimatedViewStyleRuleSet; abstract createScrollViewStyle(ruleSet: Types.ScrollViewStyle, cacheStyle?: boolean): Types.ScrollViewStyleRuleSet; abstract createButtonStyle(ruleSet: Types.ButtonStyle, cacheStyle?: boolean): Types.ButtonStyleRuleSet; abstract createTextStyle(ruleSet: Types.TextStyle, cacheStyle?: boolean): Types.TextStyleRuleSet; abstract createAnimatedTextStyle(ruleSet: Types.AnimatedTextStyle): Types.AnimatedTextStyleRuleSet; abstract createTextInputStyle(ruleSet: Types.TextInputStyle, cacheStyle?: boolean): Types.TextInputStyleRuleSet; abstract createAnimatedTextInputStyle(ruleSet: Types.AnimatedTextInputStyle): Types.AnimatedTextInputStyleRuleSet; abstract createImageStyle(ruleSet: Types.ImageStyle, cacheStyle?: boolean): Types.ImageStyleRuleSet; abstract createAnimatedImageStyle(ruleSet: Types.AnimatedImageStyle): Types.AnimatedImageStyleRuleSet; abstract createLinkStyle(ruleSet: Types.LinkStyleRuleSet, cacheStyle?: boolean): Types.LinkStyleRuleSet; abstract createPickerStyle(ruleSet: Types.PickerStyle, cacheStyle?: boolean): Types.PickerStyleRuleSet; // This method isn't part of the documented ReactXP interface and shouldn't be used by // app-level code, but it is needed for some ReactXP extensions (e.g. reactxp-imagesvg), // so we export it here. abstract getCssPropertyAliasesCssStyle(): { [key: string]: string }; } export abstract class Text extends React.Component implements FocusableComponent { abstract focus(): void; abstract requestFocus(): void; abstract blur(): void; abstract getSelectedText(): string; } export abstract class TextInput extends React.Component implements FocusableComponent { abstract setAccessibilityFocus(): void; abstract isFocused(): boolean; abstract selectAll(): void; abstract selectRange(start: number, end: number): void; abstract getSelectionRange(): { start: number; end: number; }; abstract setValue(value: string): void; abstract focus(): void; abstract requestFocus(): void; abstract blur(): void; } export abstract class UserPresence { abstract isUserPresent(): boolean; userPresenceChangedEvent = new SubscribableEvent<(isPresent: boolean) => void>(); } export abstract class ViewBase extends React.Component {} export abstract class View extends ViewBase implements FocusableComponent { abstract setFocusRestricted(restricted: boolean): void; abstract setFocusLimited(limited: boolean): void; abstract focus(): void; abstract requestFocus(): void; abstract blur(): void; } export abstract class GestureView extends ViewBase {} export interface Animated { Image: typeof AnimatedImage; Text: typeof AnimatedText; TextInput: typeof AnimatedTextInput; View: typeof AnimatedView; Easing: Types.Animated.Easing; timing: Types.Animated.TimingFunction; parallel: Types.Animated.ParallelFunction; sequence: Types.Animated.SequenceFunction; Value: typeof Types.AnimatedValue; createValue: (initialValue: number) => Types.AnimatedValue; interpolate: (value: Types.AnimatedValue, inputRange: number[], outputRange: string[]) => Types.InterpolatedValue; } export interface International { allowRTL(allow: boolean): void; forceRTL(force: boolean): void; isRTL(): boolean; }