Add spec for AndroidToast (#24888)

Summary:
part of #24875

## Changelog

[General] [Added] - Add TM spec for AndroidToast
Pull Request resolved: https://github.com/facebook/react-native/pull/24888

Reviewed By: RSNara

Differential Revision: D15543043

Pulled By: fkgozali

fbshipit-source-id: 6636dd913f7c006704ead1aa92d37e42a4edf70e
This commit is contained in:
Wojteg1337
2019-05-29 18:33:28 -07:00
committed by Facebook Github Bot
parent aaa4127332
commit 08efb1d73b
3 changed files with 66 additions and 12 deletions
@@ -0,0 +1,39 @@
/**
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @flow
* @format
*/
'use strict';
import type {TurboModule} from 'RCTExport';
import * as TurboModuleRegistry from 'TurboModuleRegistry';
export interface Spec extends TurboModule {
+getConstants: () => {|
SHORT: number,
LONG: number,
TOP: number,
BOTTOM: number,
CENTER: number,
|};
+show: (message: string, duration: number) => void;
+showWithGravity: (
message: string,
duration: number,
gravity: number,
) => void;
+showWithGravityAndOffset: (
message: string,
duration: number,
gravity: number,
xOffset: number,
yOffset: number,
) => void;
}
export default TurboModuleRegistry.getEnforcing<Spec>('ToastAndroid');
@@ -9,9 +9,7 @@
*/
'use strict';
const RCTToastAndroid = require('../../BatchedBridge/NativeModules')
.ToastAndroid;
import NativeToastAndroid from './NativeToastAndroid';
/**
* This exposes the native ToastAndroid module as a JS module. This has a function 'show'
@@ -36,16 +34,15 @@ const RCTToastAndroid = require('../../BatchedBridge/NativeModules')
const ToastAndroid = {
// Toast duration constants
SHORT: RCTToastAndroid.SHORT,
LONG: RCTToastAndroid.LONG,
SHORT: NativeToastAndroid.getConstants().SHORT,
LONG: NativeToastAndroid.getConstants().LONG,
// Toast gravity constants
TOP: RCTToastAndroid.TOP,
BOTTOM: RCTToastAndroid.BOTTOM,
CENTER: RCTToastAndroid.CENTER,
TOP: NativeToastAndroid.getConstants().TOP,
BOTTOM: NativeToastAndroid.getConstants().BOTTOM,
CENTER: NativeToastAndroid.getConstants().CENTER,
show: function(message: string, duration: number): void {
RCTToastAndroid.show(message, duration);
NativeToastAndroid.show(message, duration);
},
showWithGravity: function(
@@ -53,7 +50,7 @@ const ToastAndroid = {
duration: number,
gravity: number,
): void {
RCTToastAndroid.showWithGravity(message, duration, gravity);
NativeToastAndroid.showWithGravity(message, duration, gravity);
},
showWithGravityAndOffset: function(
@@ -63,7 +60,7 @@ const ToastAndroid = {
xOffset: number,
yOffset: number,
): void {
RCTToastAndroid.showWithGravityAndOffset(
NativeToastAndroid.showWithGravityAndOffset(
message,
duration,
gravity,
@@ -16,6 +16,24 @@ const ToastAndroid = {
show: function(message: string, duration: number): void {
warning(false, 'ToastAndroid is not supported on this platform.');
},
showWithGravity: function(
message: string,
duration: number,
gravity: number,
): void {
warning(false, 'ToastAndroid is not supported on this platform.');
},
showWithGravityAndOffset: function(
message: string,
duration: number,
gravity: number,
xOffset: number,
yOffset: number,
): void {
warning(false, 'ToastAndroid is not supported on this platform.');
},
};
module.exports = ToastAndroid;