forked from DefinitelyTyped/DefinitelyTyped
-
Notifications
You must be signed in to change notification settings - Fork 0
/
react-native.d.ts
3480 lines (2835 loc) · 119 KB
/
react-native.d.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// Type definitions for react-native 0.14
// Project: https://github.com/facebook/react-native
// Definitions by: Bruno Grieder <https://github.com/bgrieder>
// Definitions: https://github.com/borisyankov/DefinitelyTyped
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//
// USING: these definitions are meant to be used with the TSC compiler target set to ES6
//
// USAGE EXAMPLES: check the RNTSExplorer project at https://github.com/bgrieder/RNTSExplorer
//
// CONTRIBUTING: please open pull requests and make sure that the changes do not break RNTSExplorer (they should not)
// Do not hesitate to open a pull request against RNTSExplorer to provide an example for a case not covered by the current App
//
// CREDITS: This work is based on an original work made by Bernd Paradies: https://github.com/bparadie
//
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// <reference path="../react/react.d.ts" />
//so we know what is "original" React
import React = __React;
//react-native "extends" react
declare namespace __React {
/**
* Represents the completion of an asynchronous operation
* @see lib.es6.d.ts
*/
export interface Promise<T> {
/**
* Attaches callbacks for the resolution and/or rejection of the Promise.
* @param onfulfilled The callback to execute when the Promise is resolved.
* @param onrejected The callback to execute when the Promise is rejected.
* @returns A Promise for the completion of which ever callback is executed.
*/
then<TResult>( onfulfilled?: ( value: T ) => TResult | Promise<TResult>, onrejected?: ( reason: any ) => TResult | Promise<TResult> ): Promise<TResult>;
/**
* Attaches a callback for only the rejection of the Promise.
* @param onrejected The callback to execute when the Promise is rejected.
* @returns A Promise for the completion of the callback.
*/
catch( onrejected?: ( reason: any ) => T | Promise<T> ): Promise<T>;
// not in lib.es6.d.ts but called by react-native
done( callback?: ( value: T ) => void ): void;
}
export interface PromiseConstructor {
/**
* A reference to the prototype.
*/
prototype: Promise<any>;
/**
* Creates a new Promise.
* @param init A callback used to initialize the promise. This callback is passed two arguments:
* a resolve callback used resolve the promise with a value or the result of another promise,
* and a reject callback used to reject the promise with a provided reason or error.
*/
new <T>( init: ( resolve: ( value?: T | Promise<T> ) => void, reject: ( reason?: any ) => void ) => void ): Promise<T>;
<T>( init: ( resolve: ( value?: T | Promise<T> ) => void, reject: ( reason?: any ) => void ) => void ): Promise<T>;
/**
* Creates a Promise that is resolved with an array of results when all of the provided Promises
* resolve, or rejected when any Promise is rejected.
* @param values An array of Promises.
* @returns A new Promise.
*/
all<T>( values: (T | Promise<T>)[] ): Promise<T[]>;
/**
* Creates a Promise that is resolved with an array of results when all of the provided Promises
* resolve, or rejected when any Promise is rejected.
* @param values An array of values.
* @returns A new Promise.
*/
all( values: Promise<void>[] ): Promise<void>;
/**
* Creates a Promise that is resolved or rejected when any of the provided Promises are resolved
* or rejected.
* @param values An array of Promises.
* @returns A new Promise.
*/
race<T>( values: (T | Promise<T>)[] ): Promise<T>;
/**
* Creates a new rejected promise for the provided reason.
* @param reason The reason the promise was rejected.
* @returns A new rejected Promise.
*/
reject( reason: any ): Promise<void>;
/**
* Creates a new rejected promise for the provided reason.
* @param reason The reason the promise was rejected.
* @returns A new rejected Promise.
*/
reject<T>( reason: any ): Promise<T>;
/**
* Creates a new resolved promise for the provided value.
* @param value A promise.
* @returns A promise whose internal state matches the provided promise.
*/
resolve<T>( value: T | Promise<T> ): Promise<T>;
/**
* Creates a new resolved promise .
* @returns A resolved promise.
*/
resolve(): Promise<void>;
}
// @see lib.es6.d.ts
export var Promise: PromiseConstructor;
//TODO: BGR: Replace with ComponentClass ?
// node_modules/react-tools/src/classic/class/ReactClass.js
export interface ReactClass<D, P, S> {
// TODO:
}
// see react-jsx.d.ts
export function createElement<P>( type: React.ReactType,
props?: P,
...children: React.ReactNode[] ): React.ReactElement<P>;
export type Runnable = ( appParameters: any ) => void;
// Similar to React.SyntheticEvent except for nativeEvent
interface NativeSyntheticEvent<T> {
bubbles: boolean
cancelable: boolean
currentTarget: EventTarget
defaultPrevented: boolean
eventPhase: number
isTrusted: boolean
nativeEvent: T
preventDefault(): void
stopPropagation(): void
target: EventTarget
timeStamp: Date
type: string
}
export interface NativeTouchEvent {
/**
* Array of all touch events that have changed since the last event
*/
changedTouches: NativeTouchEvent[]
/**
* The ID of the touch
*/
identifier: string
/**
* The X position of the touch, relative to the element
*/
locationX: number
/**
* The Y position of the touch, relative to the element
*/
locationY: number
/**
* The X position of the touch, relative to the screen
*/
pageX: number
/**
* The Y position of the touch, relative to the screen
*/
pageY: number
/**
* The node id of the element receiving the touch event
*/
target: string
/**
* A time identifier for the touch, useful for velocity calculation
*/
timestamp: number
/**
* Array of all current touches on the screen
*/
touches : NativeTouchEvent[]
}
export interface GestureResponderEvent extends NativeSyntheticEvent<NativeTouchEvent> {
}
export interface PointProperties {
x: number
y: number
}
export interface Insets {
top?: number
left?: number
bottom?: number
right?: number
}
/**
* //FIXME: need to find documentation on which compoenent is a native (i.e. non composite component)
*/
export interface NativeComponent {
setNativeProps: ( props: Object ) => void
}
/**
* //FIXME: need to find documentation on which component is a TTouchable and can implement that interface
* @see React.DOMAtributes
*/
export interface Touchable {
onTouchStart?: ( event: GestureResponderEvent ) => void
onTouchMove?: ( event: GestureResponderEvent ) => void
onTouchEnd?: ( event: GestureResponderEvent ) => void
onTouchCancel?: ( event: GestureResponderEvent ) => void
onTouchEndCapture?: ( event: GestureResponderEvent ) => void
}
export type AppConfig = {
appKey: string;
component: ReactClass<any, any, any>;
run?: Runnable;
}
// https://github.com/facebook/react-native/blob/master/Libraries/AppRegistry/AppRegistry.js
export class AppRegistry {
static registerConfig( config: AppConfig[] ): void;
static registerComponent( appKey: string, getComponentFunc: () => React.ComponentClass<any> ): string;
static registerRunnable( appKey: string, func: Runnable ): string;
static runApplication( appKey: string, appParameters: any ): void;
}
export interface LayoutAnimationTypes {
spring: string
linear: string
easeInEaseOut: string
easeIn: string
easeOut: string
}
export interface LayoutAnimationProperties {
opacity: string
scaleXY: string
}
export interface LayoutAnimationAnim {
duration?: number
delay?: number
springDamping?: number
initialVelocity?: number
type?: string //LayoutAnimationTypes
property?: string //LayoutAnimationProperties
}
export interface LayoutAnimationConfig {
duration: number
create?: LayoutAnimationAnim
update?: LayoutAnimationAnim
delete?: LayoutAnimationAnim
}
export interface LayoutAnimationStatic {
configureNext: ( config: LayoutAnimationConfig, onAnimationDidEnd?: () => void, onError?: ( error?: any ) => void ) => void
create: ( duration: number, type?: string, creationProp?: string ) => LayoutAnimationConfig
Types: LayoutAnimationTypes
Properties: LayoutAnimationProperties
configChecker: ( conf: {config: LayoutAnimationConfig}, name: string, next: string ) => void
Presets : {
easeInEaseOut: LayoutAnimationConfig
linear:LayoutAnimationConfig
spring: LayoutAnimationConfig
}
}
/**
* Flex Prop Types
* @see https://facebook.github.io/react-native/docs/flexbox.html#proptypes
* @see LayoutPropTypes.js
*/
export interface FlexStyle {
alignItems?: string; //enum('flex-start', 'flex-end', 'center', 'stretch')
alignSelf?: string// enum('auto', 'flex-start', 'flex-end', 'center', 'stretch')
borderBottomWidth?: number
borderLeftWidth?: number
borderRightWidth?: number
borderTopWidth?: number
borderWidth?: number
bottom?: number
flex?: number
flexDirection?: string // enum('row', 'column')
flexWrap?: string // enum('wrap', 'nowrap')
height?: number
justifyContent?: string // enum('flex-start', 'flex-end', 'center', 'space-between', 'space-around')
left?: number
margin?: number
marginBottom?: number
marginHorizontal?: number
marginLeft?: number
marginRight?: number
marginTop?: number
marginVertical?: number
padding?: number
paddingBottom?: number
paddingHorizontal?: number
paddingLeft?: number
paddingRight?: number
paddingTop?: number
paddingVertical?: number
position?: string // enum('absolute', 'relative')
right?: number
top?: number
width?: number
}
export interface TransformsStyle {
transform?: [{perspective: number}, {rotate: string}, {rotateX: string}, {rotateY: string}, {rotateZ: string}, {scale: number}, {scaleX: number}, {scaleY: number}, {translateX: number}, {translateY: number}, {skewX: string}, {skewY: string}]
transformMatrix?: Array<number>
rotation?: number
scaleX?: number
scaleY?: number
translateX?: number
translateY?: number
}
export interface StyleSheetProperties {
// TODO:
}
export interface LayoutRectangle {
x: number;
y: number;
width: number;
height: number;
}
// @see TextProperties.onLayout
export interface LayoutChangeEvent {
nativeEvent: {
layout: LayoutRectangle
}
}
// @see https://facebook.github.io/react-native/docs/text.html#style
export interface TextStyle extends ViewStyle {
color?: string
fontFamily?: string
fontSize?: number
fontStyle?: string // 'normal' | 'italic';
fontWeight?: string // enum("normal", 'bold', '100', '200', '300', '400', '500', '600', '700', '800', '900')
letterSpacing?: number
lineHeight?: number
textAlign?: string // enum("auto", 'left', 'right', 'center')
textDecorationLine?: string // enum("none", 'underline', 'line-through', 'underline line-through')
textDecorationStyle?: string // enum("solid", 'double', 'dotted', 'dashed')
textDecorationColor?: string
writingDirection?: string; //enum("auto", 'ltr', 'rtl')
//containerBackgroundColor?: string
}
export interface TextPropertiesIOS {
/**
* When true, no visual change is made when text is pressed down.
* By default, a gray oval highlights the text on press down.
*/
suppressHighlighting?: boolean
}
// https://facebook.github.io/react-native/docs/text.html#props
export interface TextProperties extends React.Props<TextProperties> {
/**
* Specifies should fonts scale to respect Text Size accessibility setting on iOS.
*/
allowFontScaling?: boolean
/**
* Used to truncate the text with an elipsis after computing the text layout, including line wrapping, such that the total number of lines does not exceed this number.
*/
numberOfLines?: number
/**
* Invoked on mount and layout changes with
*
* {nativeEvent: { layout: {x, y, width, height}}}.
*/
onLayout?: ( event: LayoutChangeEvent ) => void
/**
* This function is called on press.
* Text intrinsically supports press handling with a default highlight state (which can be disabled with suppressHighlighting).
*/
onPress?: () => void
/**
* @see https://facebook.github.io/react-native/docs/text.html#style
*/
style?: TextStyle
/**
* Used to locate this view in end-to-end tests.
*/
testID?: string
}
/**
* A React component for displaying text which supports nesting, styling, and touch handling.
*/
export interface TextStatic extends React.ComponentClass<TextProperties> {
}
/**
* IOS Specific properties for TextInput
* @see https://facebook.github.io/react-native/docs/textinput.html#props
*/
export interface TextInputIOSProperties {
/**
* If true, the text field will blur when submitted.
* The default value is true.
*/
blurOnSubmit?: boolean
/**
* enum('never', 'while-editing', 'unless-editing', 'always')
* When the clear button should appear on the right side of the text view
*/
clearButtonMode?: string
/**
* If true, clears the text field automatically when editing begins
*/
clearTextOnFocus?: boolean
/**
* If true, the keyboard disables the return key when there is no text and automatically enables it when there is text.
* The default value is false.
*/
enablesReturnKeyAutomatically?: boolean
/**
* Callback that is called when a key is pressed.
* Pressed key value is passed as an argument to the callback handler.
* Fires before onChange callbacks.
*/
onKeyPress?: () => void
/**
* enum('default', 'go', 'google', 'join', 'next', 'route', 'search', 'send', 'yahoo', 'done', 'emergency-call')
* Determines how the return key should look.
*/
returnKeyType?: string
/**
* If true, all text will automatically be selected on focus
*/
selectTextOnFocus?: boolean
/**
* //FIXME: requires typing
* See DocumentSelectionState.js, some state that is responsible for maintaining selection information for a document
*/
selectionState?: any
}
/**
* Android Specific properties for TextInput
* @see https://facebook.github.io/react-native/docs/textinput.html#props
*/
export interface TextInputAndroidProperties {
/**
* Sets the number of lines for a TextInput.
* Use it with multiline set to true to be able to fill the lines.
*/
numberOfLines?: number
/**
* enum('start', 'center', 'end')
* Set the position of the cursor from where editing will begin.
*/
textAlign?: string
/**
* enum('top', 'center', 'bottom')
* Aligns text vertically within the TextInput.
*/
textAlignVertical?: string
/**
* The color of the textInput underline.
*/
underlineColorAndroid?: string
}
/**
* @see https://facebook.github.io/react-native/docs/textinput.html#props
*/
export interface TextInputProperties extends TextInputIOSProperties, TextInputAndroidProperties, React.Props<TextInputStatic> {
/**
* Can tell TextInput to automatically capitalize certain characters.
* characters: all characters,
* words: first letter of each word
* sentences: first letter of each sentence (default)
* none: don't auto capitalize anything
*
* https://facebook.github.io/react-native/docs/textinput.html#autocapitalize
*/
autoCapitalize?: string
/**
* If false, disables auto-correct.
* The default value is true.
*/
autoCorrect?: boolean
/**
* If true, focuses the input on componentDidMount.
* The default value is false.
*/
autoFocus?: boolean
/**
* Provides an initial value that will change when the user starts typing.
* Useful for simple use-cases where you don't want to deal with listening to events
* and updating the value prop to keep the controlled state in sync.
*/
defaultValue?: string
/**
* If false, text is not editable. The default value is true.
*/
editable?: boolean
/**
* enum("default", 'numeric', 'email-address', "ascii-capable", 'numbers-and-punctuation', 'url', 'number-pad', 'phone-pad', 'name-phone-pad', 'decimal-pad', 'twitter', 'web-search')
* Determines which keyboard to open, e.g.numeric.
* The following values work across platforms: - default - numeric - email-address
*/
keyboardType?: string
/**
* Limits the maximum number of characters that can be entered.
* Use this instead of implementing the logic in JS to avoid flicker.
*/
maxLength?: number
/**
* If true, the text input can be multiple lines. The default value is false.
*/
multiline?: boolean
/**
* Callback that is called when the text input is blurred
*/
onBlur?: () => void
/**
* Callback that is called when the text input's text changes.
*/
onChange?: ( event: {nativeEvent: {text: string}} ) => void
/**
* Callback that is called when the text input's text changes.
* Changed text is passed as an argument to the callback handler.
*/
onChangeText?: ( text: string ) => void
/**
* Callback that is called when text input ends.
*/
onEndEditing?: ( event: {nativeEvent: {text: string}} ) => void
/**
* Callback that is called when the text input is focused
*/
onFocus?: () => void
/**
* Invoked on mount and layout changes with {x, y, width, height}.
*/
onLayout?: ( event: {nativeEvent: {x: number, y: number, width: number, height: number}} ) => void
/**
* Callback that is called when the text input's submit button is pressed.
*/
onSubmitEditing?: ( event: {nativeEvent: {text: string}} ) => void
/**
* //FIXME: Not part of the doc but found in examples
*/
password?: boolean
/**
* The string that will be rendered before text input has been entered
*/
placeholder?: string
/**
* The text color of the placeholder string
*/
placeholderTextColor?: string
/**
* If true, the text input obscures the text entered so that sensitive text like passwords stay secure.
* The default value is false.
*/
secureTextEntry?: boolean
/**
* Styles
*/
style?: TextStyle
/**
* Used to locate this view in end-to-end tests
*/
testID?: string
/**
* The value to show for the text input. TextInput is a controlled component,
* which means the native value will be forced to match this value prop if provided.
* For most uses this works great, but in some cases this may cause flickering - one common cause is preventing edits by keeping value the same.
* In addition to simply setting the same value, either set editable={false},
* or set/update maxLength to prevent unwanted edits without flicker.
*/
value?: string
}
export interface TextInputStatic extends NativeComponent, React.ComponentClass<TextInputProperties> {
blur: () => void
focus: () => void
}
/**
* Gesture recognition on mobile devices is much more complicated than web.
* A touch can go through several phases as the app determines what the user's intention is.
* For example, the app needs to determine if the touch is scrolling, sliding on a widget, or tapping.
* This can even change during the duration of a touch. There can also be multiple simultaneous touches.
*
* The touch responder system is needed to allow components to negotiate these touch interactions
* without any additional knowledge about their parent or child components.
* This system is implemented in ResponderEventPlugin.js, which contains further details and documentation.
*
* Best Practices
* Users can feel huge differences in the usability of web apps vs. native, and this is one of the big causes.
* Every action should have the following attributes:
* Feedback/highlighting- show the user what is handling their touch, and what will happen when they release the gesture
* Cancel-ability- when making an action, the user should be able to abort it mid-touch by dragging their finger away
*
* These features make users more comfortable while using an app,
* because it allows people to experiment and interact without fear of making mistakes.
*
* TouchableHighlight and Touchable*
* The responder system can be complicated to use.
* So we have provided an abstract Touchable implementation for things that should be "tappable".
* This uses the responder system and allows you to easily configure tap interactions declaratively.
* Use TouchableHighlight anywhere where you would use a button or link on web.
*/
export interface GestureResponderHandlers {
/**
* A view can become the touch responder by implementing the correct negotiation methods.
* There are two methods to ask the view if it wants to become responder:
*/
/**
* Does this view want to become responder on the start of a touch?
*/
onStartShouldSetResponder?: ( event: GestureResponderEvent ) => boolean
/**
* Called for every touch move on the View when it is not the responder: does this view want to "claim" touch responsiveness?
*/
onMoveShouldSetResponder?: ( event: GestureResponderEvent ) => boolean
/**
* If the View returns true and attempts to become the responder, one of the following will happen:
*/
/**
* The View is now responding for touch events.
* This is the time to highlight and show the user what is happening
*/
onResponderGrant?: ( event: GestureResponderEvent ) => void
/**
* Something else is the responder right now and will not release it
*/
onResponderReject?: ( event: GestureResponderEvent ) => void
/**
* If the view is responding, the following handlers can be called:
*/
/**
* The user is moving their finger
*/
onResponderMove?: ( event: GestureResponderEvent ) => void
/**
* Fired at the end of the touch, ie "touchUp"
*/
onResponderRelease?: ( event: GestureResponderEvent ) => void
/**
* Something else wants to become responder.
* Should this view release the responder? Returning true allows release
*/
onResponderTerminationRequest?: ( event: GestureResponderEvent ) => boolean
/**
* The responder has been taken from the View.
* Might be taken by other views after a call to onResponderTerminationRequest,
* or might be taken by the OS without asking (happens with control center/ notification center on iOS)
*/
onResponderTerminate?: ( event: GestureResponderEvent ) => void
/**
* onStartShouldSetResponder and onMoveShouldSetResponder are called with a bubbling pattern,
* where the deepest node is called first.
* That means that the deepest component will become responder when multiple Views return true for *ShouldSetResponder handlers.
* This is desirable in most cases, because it makes sure all controls and buttons are usable.
*
* However, sometimes a parent will want to make sure that it becomes responder.
* This can be handled by using the capture phase.
* Before the responder system bubbles up from the deepest component,
* it will do a capture phase, firing on*ShouldSetResponderCapture.
* So if a parent View wants to prevent the child from becoming responder on a touch start,
* it should have a onStartShouldSetResponderCapture handler which returns true.
*/
onStartShouldSetResponderCapture?: ( event: GestureResponderEvent ) => boolean
/**
* onStartShouldSetResponder and onMoveShouldSetResponder are called with a bubbling pattern,
* where the deepest node is called first.
* That means that the deepest component will become responder when multiple Views return true for *ShouldSetResponder handlers.
* This is desirable in most cases, because it makes sure all controls and buttons are usable.
*
* However, sometimes a parent will want to make sure that it becomes responder.
* This can be handled by using the capture phase.
* Before the responder system bubbles up from the deepest component,
* it will do a capture phase, firing on*ShouldSetResponderCapture.
* So if a parent View wants to prevent the child from becoming responder on a touch start,
* it should have a onStartShouldSetResponderCapture handler which returns true.
*/
onMoveShouldSetResponderCapture?: () => void;
}
// @see https://facebook.github.io/react-native/docs/view.html#style
export interface ViewStyle extends FlexStyle, TransformsStyle {
backgroundColor?: string;
borderBottomColor?: string;
borderBottomLeftRadius?: number;
borderBottomRightRadius?: number;
borderColor?: string;
borderLeftColor?: string;
borderRadius?: number;
borderRightColor?: string;
borderTopColor?: string;
borderTopLeftRadius?: number;
borderTopRightRadius?: number;
opacity?: number;
overflow?: string; // enum('visible', 'hidden')
shadowColor?: string;
shadowOffset?: {width: number, height: number};
shadowOpacity?: number;
shadowRadius?: number;
}
export interface ViewPropertiesIOS {
/**
* Provides additional traits to screen reader.
* By default no traits are provided unless specified otherwise in element
*
* @enum('none', 'button', 'link', 'header', 'search', 'image', 'selected', 'plays', 'key', 'text','summary', 'disabled', 'frequentUpdates', 'startsMedia', 'adjustable', 'allowsDirectInteraction', 'pageTurn')
*/
accessibilityTraits?: string | string[];
/**
* Whether this view should be rendered as a bitmap before compositing.
*
* On iOS, this is useful for animations and interactions that do not modify this component's dimensions nor its children;
* for example, when translating the position of a static view, rasterization allows the renderer to reuse a cached bitmap of a static view
* and quickly composite it during each frame.
*
* Rasterization incurs an off-screen drawing pass and the bitmap consumes memory.
* Test and measure when using this property.
*/
shouldRasterizeIOS?: boolean
}
export interface ViewPropertiesAndroid {
/**
* Indicates to accessibility services to treat UI component like a native one.
* Works for Android only.
*
* @enum('none', 'button', 'radiobutton_checked', 'radiobutton_unchecked' )
*/
accessibilityComponentType?: string
/**
* Indicates to accessibility services whether the user should be notified when this view changes.
* Works for Android API >= 19 only.
* See http://developer.android.com/reference/android/view/View.html#attr_android:accessibilityLiveRegion for references.
*/
accessibilityLiveRegion?: string
/**
* Views that are only used to layout their children or otherwise don't draw anything
* may be automatically removed from the native hierarchy as an optimization.
* Set this property to false to disable this optimization and ensure that this View exists in the native view hierarchy.
*/
collapsable?: boolean
/**
* Controls how view is important for accessibility which is if it fires accessibility events
* and if it is reported to accessibility services that query the screen.
* Works for Android only. See http://developer.android.com/reference/android/R.attr.html#importantForAccessibility for references.
*
* Possible values:
* 'auto' - The system determines whether the view is important for accessibility - default (recommended).
* 'yes' - The view is important for accessibility.
* 'no' - The view is not important for accessibility.
* 'no-hide-descendants' - The view is not important for accessibility, nor are any of its descendant views.
*/
importantForAccessibility?: string
/**
* Whether this view needs to rendered offscreen and composited with an alpha in order to preserve 100% correct colors and blending behavior.
* The default (false) falls back to drawing the component and its children
* with an alpha applied to the paint used to draw each element instead of rendering the full component offscreen and compositing it back with an alpha value.
* This default may be noticeable and undesired in the case where the View you are setting an opacity on
* has multiple overlapping elements (e.g. multiple overlapping Views, or text and a background).
*
* Rendering offscreen to preserve correct alpha behavior is extremely expensive
* and hard to debug for non-native developers, which is why it is not turned on by default.
* If you do need to enable this property for an animation,
* consider combining it with renderToHardwareTextureAndroid if the view contents are static (i.e. it doesn't need to be redrawn each frame).
* If that property is enabled, this View will be rendered off-screen once,
* saved in a hardware texture, and then composited onto the screen with an alpha each frame without having to switch rendering targets on the GPU.
*/
needsOffscreenAlphaCompositing?: boolean
/**
* Whether this view should render itself (and all of its children) into a single hardware texture on the GPU.
*
* On Android, this is useful for animations and interactions that only modify opacity, rotation, translation, and/or scale:
* in those cases, the view doesn't have to be redrawn and display lists don't need to be re-executed. The texture can just be
* re-used and re-composited with different parameters. The downside is that this can use up limited video memory, so this prop should be set back to false at the end of the interaction/animation.
*/
renderToHardwareTextureAndroid?: boolean;
}
/**
* @see https://facebook.github.io/react-native/docs/view.html#props
*/
export interface ViewProperties extends ViewPropertiesAndroid, ViewPropertiesIOS, GestureResponderHandlers, Touchable, React.Props<ViewStatic> {
/**
* Overrides the text that's read by the screen reader when the user interacts with the element. By default, the label is constructed by traversing all the children and accumulating all the Text nodes separated by space.
*/
accessibilityLabel?: string;
/**
* When true, indicates that the view is an accessibility element.
* By default, all the touchable elements are accessible.
*/
accessible?: boolean;
/**
* When `accessible` is true, the system will try to invoke this function when the user performs accessibility tap gesture.
*/
onAcccessibilityTap?: () => void;
/**
* Invoked on mount and layout changes with
*
* {nativeEvent: { layout: {x, y, width, height}}}.
*/
onLayout?: ( event: LayoutChangeEvent ) => void;
/**
* When accessible is true, the system will invoke this function when the user performs the magic tap gesture.
*/
onMagicTap?: () => void;
/**
*
* In the absence of auto property, none is much like CSS's none value. box-none is as if you had applied the CSS class:
*
* .box-none {
* pointer-events: none;
* }
* .box-none * {
* pointer-events: all;
* }
*
* box-only is the equivalent of
*
* .box-only {
* pointer-events: all;
* }
* .box-only * {
* pointer-events: none;
* }
*
* But since pointerEvents does not affect layout/appearance, and we are already deviating from the spec by adding additional modes,
* we opt to not include pointerEvents on style. On some platforms, we would need to implement it as a className anyways. Using style or not is an implementation detail of the platform.
*/
pointerEvents?: string;
/**
*
* This is a special performance property exposed by RCTView and is useful for scrolling content when there are many subviews,
* most of which are offscreen. For this property to be effective, it must be applied to a view that contains many subviews that extend outside its bound.
* The subviews must also have overflow: hidden, as should the containing view (or one of its superviews).
*/
removeClippedSubviews?: boolean
style?: ViewStyle;
/**
* Used to locate this view in end-to-end tests.
*/
testID?: string;
}
/**
* The most fundamental component for building UI, View is a container that supports layout with flexbox, style, some touch handling,
* and accessibility controls, and is designed to be nested inside other views and to have 0 to many children of any type.
* View maps directly to the native view equivalent on whatever platform React is running on,
* whether that is a UIView, <div>, android.view, etc.
*/
export interface ViewStatic extends NativeComponent, React.ComponentClass<ViewProperties> {
}
/**
* //FIXME: No documentation extracted from code comment on WebView.ios.js
*/
export interface NavState {
url?: string
title?: string
loading?: boolean
canGoBack?: boolean
canGoForward?: boolean;
[key: string]: any
}
export interface WebViewPropertiesAndroid {
/**
* Used for android only, JS is enabled by default for WebView on iOS
*/