-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
fac74b0
commit 18173ca
Showing
7 changed files
with
108 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
35 changes: 35 additions & 0 deletions
35
react-native/components/createLimitedWidthComponent/index.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import * as React from "react"; | ||
import { StyleSheet, View } from "react-native"; | ||
|
||
/** | ||
* Creates a React component which has a maximum width. | ||
* @param maximumWidth The maximum width of the component | ||
* @returns The created component. | ||
*/ | ||
export const createLimitedWidthComponent = ( | ||
maximumWidth: number | ||
): React.FunctionComponent<{ | ||
/** Determines how the column is to be sized vertically. */ | ||
readonly height: `fillsContainer` | `fitsContent`; | ||
}> => { | ||
const styles = StyleSheet.create({ | ||
fillsContainer: { | ||
maxWidth: maximumWidth, | ||
height: `100%`, | ||
}, | ||
fitsContent: { | ||
maxWidth: maximumWidth, | ||
}, | ||
}); | ||
|
||
return ({ children, height }) => ( | ||
<View | ||
style={ | ||
height === `fillsContainer` ? styles.fillsContainer : styles.fitsContent | ||
} | ||
pointerEvents="box-none" | ||
> | ||
{children} | ||
</View> | ||
); | ||
}; |
29 changes: 29 additions & 0 deletions
29
react-native/components/createLimitedWidthComponent/readme.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
# `react-native-app-helpers/createLimitedWidthComponent` | ||
|
||
Creates a React component which has a maximum width. | ||
|
||
## Usage | ||
|
||
```tsx | ||
import { createLimitedWidthComponent } from "react-native-app-helpers"; | ||
|
||
const ExampleComponent = createLimitedWidthComponent(243); | ||
|
||
const ExampleScreen = () => ( | ||
<ExampleComponent height="fillsContainer"> | ||
<Text>This is up to 243 wide and fills its container vertically.</Text> | ||
</ExampleComponent> | ||
); | ||
``` | ||
|
||
```tsx | ||
import { createLimitedWidthComponent } from "react-native-app-helpers"; | ||
|
||
const ExampleComponent = createLimitedWidthComponent(243); | ||
|
||
const ExampleScreen = () => ( | ||
<ExampleComponent height="fitsContent"> | ||
<Text>This is up to 243 wide and fits its content vertically.</Text> | ||
</ExampleComponent> | ||
); | ||
``` |
38 changes: 38 additions & 0 deletions
38
react-native/components/createLimitedWidthComponent/unit.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import * as React from "react"; | ||
import { Text, View } from "react-native"; | ||
import { | ||
createLimitedWidthComponent, | ||
unwrapRenderedFunctionComponent, | ||
} from "../../.."; | ||
|
||
test(`renders as expected when filling its container vertically`, () => { | ||
const Component = createLimitedWidthComponent(243); | ||
|
||
const rendered = ( | ||
<Component height="fillsContainer"> | ||
<Text>Example Content</Text> | ||
</Component> | ||
); | ||
|
||
expect(unwrapRenderedFunctionComponent(rendered)).toEqual( | ||
<View style={{ maxWidth: 243, height: `100%` }} pointerEvents="box-none"> | ||
<Text>Example Content</Text> | ||
</View> | ||
); | ||
}); | ||
|
||
test(`renders as expected when fitting its content vertically`, () => { | ||
const Component = createLimitedWidthComponent(243); | ||
|
||
const rendered = ( | ||
<Component height="fitsContent"> | ||
<Text>Example Content</Text> | ||
</Component> | ||
); | ||
|
||
expect(unwrapRenderedFunctionComponent(rendered)).toEqual( | ||
<View style={{ maxWidth: 243 }} pointerEvents="box-none"> | ||
<Text>Example Content</Text> | ||
</View> | ||
); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters