MCPcopy
hub / github.com/callstack/react-native-paper / Banner

Function Banner

src/components/Banner.tsx:119–259  ·  view source on GitHub ↗
({
  visible,
  icon,
  children,
  actions = [],
  contentStyle,
  elevation = 1,
  style,
  theme: themeOverrides,
  onShowAnimationFinished = () => {},
  onHideAnimationFinished = () => {},
  maxFontSizeMultiplier,
  ...rest
}: Props)

Source from the content-addressed store, hash-verified

117 * ```
118 */
119const Banner = ({
120 visible,
121 icon,
122 children,
123 actions = [],
124 contentStyle,
125 elevation = 1,
126 style,
127 theme: themeOverrides,
128 onShowAnimationFinished = () => {},
129 onHideAnimationFinished = () => {},
130 maxFontSizeMultiplier,
131 ...rest
132}: Props) => {
133 const theme = useInternalTheme(themeOverrides);
134 const { current: position } = React.useRef<Animated.Value>(
135 new Animated.Value(visible ? 1 : 0)
136 );
137 const [layout, setLayout] = React.useState<{
138 height: number;
139 measured: boolean;
140 }>({
141 height: 0,
142 measured: false,
143 });
144
145 const showCallback = useLatestCallback(onShowAnimationFinished);
146 const hideCallback = useLatestCallback(onHideAnimationFinished);
147
148 const { scale } = theme.animation;
149
150 const opacity = position.interpolate({
151 inputRange: [0, 0.1, 1],
152 outputRange: [0, 1, 1],
153 });
154
155 React.useEffect(() => {
156 if (visible) {
157 // show
158 Animated.timing(position, {
159 duration: 250 * scale,
160 toValue: 1,
161 useNativeDriver: false,
162 }).start(showCallback);
163 } else {
164 // hide
165 Animated.timing(position, {
166 duration: 200 * scale,
167 toValue: 0,
168 useNativeDriver: false,
169 }).start(hideCallback);
170 }
171 // eslint-disable-next-line react-hooks/exhaustive-deps
172 }, [visible, position, scale]);
173
174 const handleLayout = ({ nativeEvent }: LayoutChangeEvent) => {
175 const { height } = nativeEvent.layout;
176 setLayout({ height, measured: true });

Callers

nothing calls this directly

Calls 1

useInternalThemeFunction · 0.90

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…