Add height provider (#75)

This commit is contained in:
Maria Rushkova 2021-10-15 16:30:41 +02:00 committed by GitHub
parent 345e5772e7
commit 5dc0bd335b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 18 additions and 3 deletions

View File

@ -2,6 +2,7 @@ import { Picker } from "emoji-mart";
import React, { useCallback, useMemo, useState } from "react";
import styled from "styled-components";
import { useLow } from "../../contexts/narrowProvider";
import { uintToImgUrl } from "../../helpers/uintToImgUrl";
import { lightTheme, Theme } from "../../styles/themes";
import { EmojiIcon } from "../Icons/EmojiIcon";
@ -59,6 +60,8 @@ export function ChatInput({ theme, addMessage }: ChatInputProps) {
[content, imageUint]
);
const low = useLow();
return (
<View>
{showEmoji && (
@ -74,6 +77,8 @@ export function ChatInput({ theme, addMessage }: ChatInputProps) {
bottom: "100%",
right: "0",
color: theme.secondary,
height: low ? "200px" : "355px",
overflow: "auto",
}}
showPreview={false}
showSkinTones={false}

View File

@ -2,10 +2,19 @@ import React, { createContext, useContext } from "react";
import { useRefBreak } from "../hooks/useRefBreak";
const NarrowContext = createContext<boolean>(false);
const NarrowContext = createContext<{ narrow: boolean; low: boolean }>({
narrow: false,
low: false,
});
export function useNarrow() {
return useContext(NarrowContext);
const { narrow } = useContext(NarrowContext);
return narrow;
}
export function useLow() {
const { low } = useContext(NarrowContext);
return low;
}
interface NarrowProviderProps {
@ -15,5 +24,6 @@ interface NarrowProviderProps {
export function NarrowProvider({ children, myRef }: NarrowProviderProps) {
const narrow = useRefBreak(myRef?.current?.offsetWidth ?? 0, 736);
return <NarrowContext.Provider value={narrow} children={children} />;
const low = useRefBreak(myRef?.current?.offsetHeight ?? 0, 465);
return <NarrowContext.Provider value={{ narrow, low }} children={children} />;
}