File tree 7 files changed +130
-0
lines changed
components/createFixedHeightComponent
7 files changed +130
-0
lines changed Original file line number Diff line number Diff line change @@ -9,6 +9,7 @@ export { createCheckboxComponent } from './react-native/components/createCheckbo
9
9
export { createCreatableSelectComponent } from './react-native/components/createCreatableSelectComponent'
10
10
export { createFileStoreManagerComponent } from './react-native/components/createFileStoreManagerComponent'
11
11
export { createFiniteStateMachineRoutingComponent } from './react-native/components/createFiniteStateMachineRoutingComponent'
12
+ export { createFixedHeightComponent } from './react-native/components/createFixedHeightComponent'
12
13
export { createFixedWidthComponent } from './react-native/components/createFixedWidthComponent'
13
14
export { createFlashMessageComponent } from './react-native/components/createFlashMessageComponent'
14
15
export { createFlatColorBackgroundComponent } from './react-native/components/createFlatColorBackgroundComponent'
@@ -106,6 +107,7 @@ export type { FileRequestBody } from './react-native/types/FileRequestBody'
106
107
export type { FileStoreInterface } from './react-native/types/FileStoreInterface'
107
108
export type { FiniteStateMachineRouterState } from './react-native/types/FiniteStateMachineRouterState'
108
109
export type { FiniteStateMachineRoutingProps } from './react-native/types/FiniteStateMachineRoutingProps'
110
+ export type { FixedHeightProps } from './react-native/types/FixedHeightProps'
109
111
export type { FixedWidthProps } from './react-native/types/FixedWidthProps'
110
112
export type { FlashMessageProps } from './react-native/types/FlashMessageProps'
111
113
export type { FlashMessageState } from './react-native/types/FlashMessageState'
Original file line number Diff line number Diff line change
1
+ import * as React from 'react'
2
+ import { StyleSheet , View } from 'react-native'
3
+ import type { FixedHeightProps } from '../../types/FixedHeightProps'
4
+
5
+ /**
6
+ * Creates a React component which has a fixed height.
7
+ * @param height The height of the component
8
+ * @returns The created component.
9
+ */
10
+ export const createFixedHeightComponent = (
11
+ height : number
12
+ ) : React . FunctionComponent < FixedHeightProps > => {
13
+ const styles = StyleSheet . create ( {
14
+ fillsContainer : {
15
+ height,
16
+ width : '100%'
17
+ } ,
18
+ fitsContent : {
19
+ height
20
+ }
21
+ } )
22
+
23
+ const FixedHeight : React . FunctionComponent < FixedHeightProps > = ( { children, width } ) => (
24
+ < View
25
+ style = {
26
+ width === 'fillsContainer' ? styles . fillsContainer : styles . fitsContent
27
+ }
28
+ pointerEvents = "box-none"
29
+ >
30
+ { children }
31
+ </ View >
32
+ )
33
+
34
+ return FixedHeight
35
+ }
Original file line number Diff line number Diff line change
1
+ # ` react-native-app-helpers/createFixedHeightComponent `
2
+
3
+ Creates a React component which has a fixed height.
4
+
5
+ ## Usage
6
+
7
+ ``` tsx
8
+ import { createFixedHeightComponent } from " react-native-app-helpers" ;
9
+
10
+ const ExampleComponent = createFixedHeightComponent (243 );
11
+
12
+ const ExampleScreen = () => (
13
+ <ExampleComponent width = " fillsContainer" >
14
+ <Text >This is 243 wide and fills its container horizontally.</Text >
15
+ </ExampleComponent >
16
+ );
17
+ ```
18
+
19
+ ``` tsx
20
+ import { createFixedHeightComponent } from " react-native-app-helpers" ;
21
+
22
+ const ExampleComponent = createFixedHeightComponent (243 );
23
+
24
+ const ExampleScreen = () => (
25
+ <ExampleComponent width = " fitsContent" >
26
+ <Text >This is 243 wide and fits its content horizontally.</Text >
27
+ </ExampleComponent >
28
+ );
29
+ ```
Original file line number Diff line number Diff line change
1
+ import * as React from 'react'
2
+ import { Text , View } from 'react-native'
3
+ import {
4
+ createFixedHeightComponent ,
5
+ unwrapRenderedFunctionComponent
6
+ } from '../../..'
7
+
8
+ test ( 'renders as expected when filling its container vertically' , ( ) => {
9
+ const Component = createFixedHeightComponent ( 243 )
10
+
11
+ const rendered = (
12
+ < Component width = "fillsContainer" >
13
+ < Text > Example Content</ Text >
14
+ </ Component >
15
+ )
16
+
17
+ expect ( unwrapRenderedFunctionComponent ( rendered ) ) . toEqual (
18
+ < View style = { { height : 243 , width : '100%' } } pointerEvents = "box-none" >
19
+ < Text > Example Content</ Text >
20
+ </ View >
21
+ )
22
+ } )
23
+
24
+ test ( 'renders as expected when fitting its content vertically' , ( ) => {
25
+ const Component = createFixedHeightComponent ( 243 )
26
+
27
+ const rendered = (
28
+ < Component width = "fitsContent" >
29
+ < Text > Example Content</ Text >
30
+ </ Component >
31
+ )
32
+
33
+ expect ( unwrapRenderedFunctionComponent ( rendered ) ) . toEqual (
34
+ < View style = { { height : 243 } } pointerEvents = "box-none" >
35
+ < Text > Example Content</ Text >
36
+ </ View >
37
+ )
38
+ } )
Original file line number Diff line number Diff line change
1
+ import type * as React from 'react'
2
+
3
+ /**
4
+ * Props to be given to fixed height components.
5
+ */
6
+ export type FixedHeightProps = React . PropsWithChildren < {
7
+ /**
8
+ * Describes how the component's widthwidth should be sized.
9
+ */
10
+ readonly width : 'fillsContainer' | 'fitsContent'
11
+ } >
Original file line number Diff line number Diff line change
1
+ # ` react-native-app-helpers/FixedHeightProps `
2
+
3
+ Props to be given to fixed height components.
4
+
5
+ ## Usage
6
+
7
+ ``` tsx
8
+ import type { FixedHeightProps } from " react-native-app-helpers" ;
9
+
10
+ const example: FixedHeightProps = {
11
+ width: " fitsContent" ,
12
+ };
13
+ ```
Original file line number Diff line number Diff line change @@ -29,6 +29,7 @@ import { createTextComponent } from "react-native-app-helpers";
29
29
- [ createCreatableSelectComponent] ( ./react-native/components/createCreatableSelectComponent/readme.md )
30
30
- [ createFileStoreManagerComponent] ( ./react-native/components/createFileStoreManagerComponent/readme.md )
31
31
- [ createFiniteStateMachineRoutingComponent] ( ./react-native/components/createFiniteStateMachineRoutingComponent/readme.md )
32
+ - [ createFixedHeightComponent] ( ./react-native/components/createFixedHeightComponent/readme.md )
32
33
- [ createFixedWidthComponent] ( ./react-native/components/createFixedWidthComponent/readme.md )
33
34
- [ createFlashMessageComponent] ( ./react-native/components/createFlashMessageComponent/readme.md )
34
35
- [ createFlatColorBackgroundComponent] ( ./react-native/components/createFlatColorBackgroundComponent/readme.md )
@@ -126,6 +127,7 @@ import { createTextComponent } from "react-native-app-helpers";
126
127
- [ FileRequestBody] ( ./react-native/types/FileRequestBody/readme.md )
127
128
- [ FiniteStateMachineRouterState] ( ./react-native/types/FiniteStateMachineRouterState/readme.md )
128
129
- [ FiniteStateMachineRoutingProps] ( ./react-native/types/FiniteStateMachineRoutingProps/readme.md )
130
+ - [ FixedHeightProps] ( ./react-native/types/FixedHeightProps/readme.md )
129
131
- [ FixedWidthProps] ( ./react-native/types/FixedWidthProps/readme.md )
130
132
- [ FlashMessageProps] ( ./react-native/types/FlashMessageProps/readme.md )
131
133
- [ FlashMessageState] ( ./react-native/types/FlashMessageState/readme.md )
You can’t perform that action at this time.
0 commit comments