Skip to content

Commit 28d2e67

Browse files
authored
feat: add typescript typings (#1)
1 parent 3451057 commit 28d2e67

File tree

5 files changed

+222
-9
lines changed

5 files changed

+222
-9
lines changed

.circleci/config.yml

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,11 @@ aliases:
8181
name: Jest Unit Tests
8282
command: yarn test:jest
8383

84+
- &tsc
85+
name: TypeScript Checks
86+
command: yarn test:tsc
87+
88+
8489
# -------------------------
8590
# JOBS
8691
# -------------------------
@@ -133,7 +138,15 @@ jobs:
133138
- attach_workspace:
134139
at: ~/toolbar-android
135140
- run: *jest
136-
141+
142+
tsc:
143+
<<: *linux_defaults
144+
steps:
145+
- attach_workspace:
146+
at: ~/toolbar-android
147+
- run: *tsc
148+
149+
137150
example-61-android-compile:
138151
<<: *android_defaults
139152
steps:
@@ -184,6 +197,9 @@ workflows:
184197
- jest:
185198
requires:
186199
- linux-checkout
200+
- tsc:
201+
requires:
202+
- linux-checkout
187203
- example-61-android-compile:
188204
requires:
189205
- linux-checkout

index.d.ts

Lines changed: 150 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,150 @@
1+
// Type definitions for @react-native-community/toolbar-android
2+
// Type definitions based off what was originally implemented in @types/react-native
3+
4+
import React from 'react';
5+
import {ImageURISource, NativeMethodsMixin, ViewProps} from 'react-native';
6+
7+
type Constructor<T> = new (...args: any[]) => T;
8+
9+
declare module '@react-native-community/toolbar-android' {
10+
export type ToolbarAndroidAction = {
11+
/**
12+
* title: required, the title of this action
13+
*/
14+
title: string;
15+
16+
/**
17+
* icon: the icon for this action, e.g. require('./some_icon.png')
18+
*/
19+
icon?: ImageURISource;
20+
21+
/**
22+
* show: when to show this action as an icon or hide it in the overflow menu: always, ifRoom or never
23+
*/
24+
show?: 'always' | 'ifRoom' | 'never';
25+
26+
/**
27+
* showWithText: boolean, whether to show text alongside the icon or not
28+
*/
29+
showWithText?: boolean;
30+
};
31+
32+
export interface ToolbarAndroidProps extends ViewProps {
33+
/**
34+
* Sets possible actions on the toolbar as part of the action menu. These are displayed as icons
35+
* or text on the right side of the widget. If they don't fit they are placed in an 'overflow'
36+
* menu.
37+
*
38+
* This property takes an array of objects, where each object has the following keys:
39+
*
40+
* * `title`: **required**, the title of this action
41+
* * `icon`: the icon for this action, e.g. `require('./some_icon.png')`
42+
* * `show`: when to show this action as an icon or hide it in the overflow menu: `always`,
43+
* `ifRoom` or `never`
44+
* * `showWithText`: boolean, whether to show text alongside the icon or not
45+
*/
46+
actions?: ToolbarAndroidAction[];
47+
48+
/**
49+
* Sets the content inset for the toolbar ending edge.
50+
* The content inset affects the valid area for Toolbar content other
51+
* than the navigation button and menu. Insets define the minimum
52+
* margin for these components and can be used to effectively align
53+
* Toolbar content along well-known gridlines.
54+
*/
55+
contentInsetEnd?: number;
56+
57+
/**
58+
* Sets the content inset for the toolbar starting edge.
59+
* The content inset affects the valid area for Toolbar content
60+
* other than the navigation button and menu. Insets define the
61+
* minimum margin for these components and can be used to effectively
62+
* align Toolbar content along well-known gridlines.
63+
*/
64+
contentInsetStart?: number;
65+
66+
/**
67+
* Sets the toolbar logo.
68+
*/
69+
logo?: ImageURISource;
70+
71+
/**
72+
* Sets the navigation icon.
73+
*/
74+
navIcon?: ImageURISource;
75+
76+
/**
77+
* Callback that is called when an action is selected. The only
78+
* argument that is passed to the callback is the position of the
79+
* action in the actions array.
80+
*/
81+
onActionSelected?: (position: number) => void;
82+
83+
/**
84+
* Callback called when the icon is selected.
85+
*/
86+
onIconClicked?: () => void;
87+
88+
/**
89+
* Sets the overflow icon.
90+
*/
91+
overflowIcon?: ImageURISource;
92+
93+
/**
94+
* Used to set the toolbar direction to RTL.
95+
* In addition to this property you need to add
96+
* android:supportsRtl="true"
97+
* to your application AndroidManifest.xml and then call
98+
* setLayoutDirection(LayoutDirection.RTL) in your MainActivity
99+
* onCreate method.
100+
*/
101+
rtl?: boolean;
102+
103+
/**
104+
* Sets the toolbar subtitle.
105+
*/
106+
subtitle?: string;
107+
108+
/**
109+
* Sets the toolbar subtitle color.
110+
*/
111+
subtitleColor?: string;
112+
113+
/**
114+
* Used to locate this view in end-to-end tests.
115+
*/
116+
testID?: string;
117+
118+
/**
119+
* Sets the toolbar title.
120+
*/
121+
title?: string;
122+
123+
/**
124+
* Sets the toolbar title color.
125+
*/
126+
titleColor?: string;
127+
}
128+
129+
/**
130+
* React component that wraps the Android-only [`Toolbar` widget][0]. A Toolbar can display a logo,
131+
* navigation icon (e.g. hamburger menu), a title & subtitle and a list of actions. The title and
132+
* subtitle are expanded so the logo and navigation icons are displayed on the left, title and
133+
* subtitle in the middle and the actions on the right.
134+
*
135+
* If the toolbar has an only child, it will be displayed between the title and actions.
136+
*
137+
* Although the Toolbar supports remote images for the logo, navigation and action icons, this
138+
* should only be used in DEV mode where `require('./some_icon.png')` translates into a packager
139+
* URL. In release mode you should always use a drawable resource for these icons. Using
140+
* `require('./some_icon.png')` will do this automatically for you, so as long as you don't
141+
* explicitly use e.g. `{uri: 'http://...'}`, you will be good.
142+
*
143+
* [0]: https://developer.android.com/reference/android/support/v7/widget/Toolbar.html
144+
*/
145+
class ToolbarAndroidComponent extends React.Component<ToolbarAndroidProps> {}
146+
const ToolbarAndroidBase: Constructor<NativeMethodsMixin> &
147+
typeof ToolbarAndroidComponent;
148+
class ToolbarAndroid extends ToolbarAndroidBase {}
149+
export default ToolbarAndroid;
150+
}

package.json

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,15 @@
1515
"license": "MIT",
1616
"author": "Connectdotz <[email protected]>",
1717
"main": "js/ToolbarAndroid",
18+
"types": "index.d.ts",
1819
"scripts": {
1920
"pack:npm": "npm pack",
20-
"ci:test:flow": "yarn test:flow",
21-
"ci:test:js": "yarn test:js",
2221
"start": "node node_modules/react-native/local-cli/cli.js start",
23-
"test": "yarn test:eslint && yarn test:flow && yarn test:jest",
22+
"test": "yarn test:eslint && yarn test:flow && yarn test:jest && yarn test:tsc",
2423
"test:eslint": "eslint .",
2524
"test:flow": "flow check",
26-
"test:jest": "jest"
25+
"test:jest": "jest",
26+
"test:tsc":"tsc --noEmit"
2727
},
2828
"prettier": {
2929
"bracketSpacing": false,
@@ -42,7 +42,8 @@
4242
"dependencies": {},
4343
"devDependencies": {
4444
"@babel/plugin-proposal-class-properties": "^7.4.0",
45-
"@react-native-community/eslint-config": "^0.0.7",
45+
"@react-native-community/eslint-config":"0.0.7",
46+
"@types/react-native": "^0.61.7",
4647
"babel-core": "^7.0.0-bridge.0",
4748
"babel-eslint": "^10.0.1",
4849
"babel-plugin-module-resolver": "^3.1.3",
@@ -54,7 +55,8 @@
5455
"prettier": "^1.16.4",
5556
"react": "16.6.3",
5657
"react-native": "0.58.4",
57-
"react-test-renderer": "^16.8.6"
58+
"react-test-renderer": "^16.8.6",
59+
"typescript": "3.7.5"
5860
},
5961
"peerDependencies": {
6062
"react": "*",
@@ -70,4 +72,4 @@
7072
"doc": "doc",
7173
"example": "example"
7274
}
73-
}
75+
}

tsconfig.json

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{
2+
"compilerOptions": {
3+
/* Basic Options */
4+
"target": "es5", /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', 'ES2018', 'ES2019' or 'ESNEXT'. */
5+
"module": "commonjs", /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', or 'ESNext'. */
6+
"jsx":"react",
7+
"lib":["es6"],
8+
"noEmit": true, /* Do not emit outputs. */
9+
/* Strict Type-Checking Options */
10+
"strict": true, /* Enable all strict type-checking options. */
11+
"esModuleInterop": true /* Enables emit interoperability between CommonJS and ES Modules via creation of namespace objects for all imports. Implies 'allowSyntheticDefaultImports'. */
12+
}
13+
}

yarn.lock

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -710,7 +710,7 @@
710710
"@types/istanbul-lib-coverage" "^2.0.0"
711711
"@types/yargs" "^12.0.9"
712712

713-
"@react-native-community/eslint-config@^0.0.7":
713+
"@react-native-community/[email protected]":
714714
version "0.0.7"
715715
resolved "https://registry.yarnpkg.com/@react-native-community/eslint-config/-/eslint-config-0.0.7.tgz#2a91d336b413d8c77ac5fa634b66703f481243ac"
716716
integrity sha512-khKxg3BMsXZYSXLat0ygSqTM0KdgciK+gm+hGecM7HzQA10hNTKeMmoFNiNxV+M/5PUyTsnRAz4RtWPVWLuPfQ==
@@ -777,6 +777,26 @@
777777
resolved "https://registry.yarnpkg.com/@types/json-schema/-/json-schema-7.0.4.tgz#38fd73ddfd9b55abb1e1b2ed578cb55bd7b7d339"
778778
integrity sha512-8+KAKzEvSUdeo+kmqnKrqgeE+LcA0tjYWFY7RPProVYwnqDjukzO+3b6dLD56rYX5TdWejnEOLJYOIeh4CXKuA==
779779

780+
"@types/prop-types@*":
781+
version "15.7.3"
782+
resolved "https://registry.yarnpkg.com/@types/prop-types/-/prop-types-15.7.3.tgz#2ab0d5da2e5815f94b0b9d4b95d1e5f243ab2ca7"
783+
integrity sha512-KfRL3PuHmqQLOG+2tGpRO26Ctg+Cq1E01D2DMriKEATHgWLfeNDmq9e29Q9WIky0dQ3NPkd1mzYH8Lm936Z9qw==
784+
785+
"@types/react-native@^0.61.7":
786+
version "0.61.7"
787+
resolved "https://registry.yarnpkg.com/@types/react-native/-/react-native-0.61.7.tgz#e0315b5f627d61470c7f58d7298e732aab90b2c5"
788+
integrity sha512-LUhIiZUfGA0+2+/+KeHDpHfBmVYZdw1vwikYF2yTap5duuXtw3SUYn6kiPyBwFf++PmhWJeGeId94vAYbptvaw==
789+
dependencies:
790+
"@types/react" "*"
791+
792+
"@types/react@*":
793+
version "16.9.19"
794+
resolved "https://registry.yarnpkg.com/@types/react/-/react-16.9.19.tgz#c842aa83ea490007d29938146ff2e4d9e4360c40"
795+
integrity sha512-LJV97//H+zqKWMms0kvxaKYJDG05U2TtQB3chRLF8MPNs+MQh/H1aGlyDUxjaHvu08EAGerdX2z4LTBc7ns77A==
796+
dependencies:
797+
"@types/prop-types" "*"
798+
csstype "^2.2.0"
799+
780800
"@types/stack-utils@^1.0.1":
781801
version "1.0.1"
782802
resolved "https://registry.yarnpkg.com/@types/stack-utils/-/stack-utils-1.0.1.tgz#0a851d3bd96498fa25c33ab7278ed3bd65f06c3e"
@@ -1603,6 +1623,11 @@ cssstyle@^1.0.0:
16031623
dependencies:
16041624
cssom "0.3.x"
16051625

1626+
csstype@^2.2.0:
1627+
version "2.6.8"
1628+
resolved "https://registry.yarnpkg.com/csstype/-/csstype-2.6.8.tgz#0fb6fc2417ffd2816a418c9336da74d7f07db431"
1629+
integrity sha512-msVS9qTuMT5zwAGCVm4mxfrZ18BNc6Csd0oJAtiFMZ1FAx1CCvy2+5MDmYoix63LM/6NDbNtodCiGYGmFgO0dA==
1630+
16061631
dashdash@^1.12.0:
16071632
version "1.14.1"
16081633
resolved "https://registry.yarnpkg.com/dashdash/-/dashdash-1.14.1.tgz#853cfa0f7cbe2fed5de20326b8dd581035f6e2f0"
@@ -2177,6 +2202,7 @@ fast-deep-equal@^2.0.1:
21772202
fast-diff@^1.1.1, fast-diff@^1.1.2:
21782203
version "1.2.0"
21792204
resolved "https://registry.yarnpkg.com/fast-diff/-/fast-diff-1.2.0.tgz#73ee11982d86caaf7959828d519cfe927fac5f03"
2205+
integrity sha512-xJuoT5+L99XlZ8twedaRf6Ax2TgQVxvgZOYoPKqZufmJib0tL2tegPBOZb1pVNgIhlqDlA0eO0c3wBvQcmzx4w==
21802206

21812207
fast-json-stable-stringify@^2.0.0:
21822208
version "2.0.0"
@@ -4605,6 +4631,7 @@ prompts@^2.0.1:
46054631
prop-types@^15.5.8, prop-types@^15.6.2, prop-types@^15.7.2:
46064632
version "15.7.2"
46074633
resolved "https://registry.yarnpkg.com/prop-types/-/prop-types-15.7.2.tgz#52c41e75b8c87e72b9d9360e0206b99dcbffa6c5"
4634+
integrity sha512-8QQikdH7//R2vurIJSutZ1smHYTcLpRWEOlHnzcWHmBYrOGUysKwSsrC89BCiFj3CbrfJ/nXFdJepOVrY1GCHQ==
46084635
dependencies:
46094636
loose-envify "^1.4.0"
46104637
object-assign "^4.1.1"
@@ -5627,6 +5654,11 @@ typedarray@^0.0.6:
56275654
version "0.0.6"
56285655
resolved "https://registry.yarnpkg.com/typedarray/-/typedarray-0.0.6.tgz#867ac74e3864187b1d3d47d996a78ec5c8830777"
56295656

5657+
5658+
version "3.7.5"
5659+
resolved "https://registry.yarnpkg.com/typescript/-/typescript-3.7.5.tgz#0692e21f65fd4108b9330238aac11dd2e177a1ae"
5660+
integrity sha512-/P5lkRXkWHNAbcJIiHPfRoKqyd7bsyCma1hZNUGfn20qm64T6ZBlrzprymeu918H+mB/0rIg2gGK/BXkhhYgBw==
5661+
56305662
ua-parser-js@^0.7.18:
56315663
version "0.7.19"
56325664
resolved "https://registry.yarnpkg.com/ua-parser-js/-/ua-parser-js-0.7.19.tgz#94151be4c0a7fb1d001af7022fdaca4642659e4b"

0 commit comments

Comments
 (0)