Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Text component #3202

Merged
merged 36 commits into from
Dec 12, 2024
Merged
Changes from 1 commit
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
c75899e
Add Text component
m-bert Nov 8, 2024
5109ee6
Add TextHook
m-bert Nov 8, 2024
3887041
simplify hook
m-bert Nov 8, 2024
c9b00a2
Fix Text activation
m-bert Nov 8, 2024
6665ddb
Add eslint no-redeclare
m-bert Nov 8, 2024
0a0da87
Merge branch 'main' into @mbert/add-GH-Text
m-bert Nov 8, 2024
1852e67
Change early return
m-bert Nov 8, 2024
5697078
Change to TextViewHook
m-bert Nov 8, 2024
45fa273
Merge branch 'main' into @mbert/add-GH-Text
m-bert Nov 13, 2024
9d02ed8
Move to separate file
m-bert Nov 13, 2024
a5ef09f
Merge branch 'main' into @mbert/add-GH-Text
m-bert Nov 15, 2024
6b80044
Fix Text on web
m-bert Nov 15, 2024
03f6289
Remove disallowInterruption flag
m-bert Nov 15, 2024
8a0e06f
Switch to new API
m-bert Nov 18, 2024
7470f98
Merge branch 'main' into @mbert/add-GH-Text
m-bert Nov 21, 2024
414e507
Merge branch 'main' into @mbert/add-GH-Text
m-bert Nov 21, 2024
5a4bc5f
Add Text on iOS
m-bert Nov 21, 2024
0447e40
onPress
m-bert Nov 21, 2024
8f1eb1d
Merge branch 'main' into @mbert/add-GH-Text
m-bert Nov 21, 2024
7e66b08
Macos
m-bert Nov 21, 2024
2d90e76
Add example
m-bert Nov 21, 2024
6477492
Fix example
m-bert Nov 21, 2024
7ae6e39
Remove newline
m-bert Nov 21, 2024
185b92d
Merge branch 'main' into @mbert/add-GH-Text
m-bert Nov 28, 2024
31aba7a
Move to lowercased convention
m-bert Nov 28, 2024
40e5322
Add hook method
m-bert Nov 28, 2024
0ade4c0
Change ref to refHandler
m-bert Nov 28, 2024
dd02ac1
Extract check to method
m-bert Nov 28, 2024
9c4cea4
Merge branch 'main' into @mbert/add-GH-Text
m-bert Dec 2, 2024
280d62e
Remove explicit children
m-bert Dec 4, 2024
da90c04
Merge branch 'main' into @mbert/add-GH-Text
m-bert Dec 4, 2024
9ada0d6
Mergele main
m-bert Dec 5, 2024
df1c2aa
Change hook
m-bert Dec 6, 2024
dbce3f8
Use cast
m-bert Dec 6, 2024
65ea0f9
Remove text from recognizer
m-bert Dec 6, 2024
794ef90
Fix macos build
m-bert Dec 9, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
77 changes: 49 additions & 28 deletions src/components/Text.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
import React, { forwardRef, Ref, RefObject, useEffect, useRef } from 'react';
import React, {
ForwardedRef,
forwardRef,
RefObject,
useEffect,
useRef,
} from 'react';
import {
Platform,
Text as RNText,
Expand All @@ -7,32 +13,47 @@ import {

import { Gesture, GestureDetector } from '../';

export const Text = forwardRef((props: RNTextProps, ref: Ref<RNText>) => {
const { children, onPress, ...rest } = props;

const textRef = useRef<RNText>(null);
const native = Gesture.Native().runOnJS(true);

useEffect(() => {
if (Platform.OS !== 'web') {
return;
}

const textElement = ref
? (ref as RefObject<RNText>).current
: textRef.current;

// @ts-ignore at this point we are sure that text is div
textElement?.setAttribute('rnghtext', 'true');
}, []);

return (
<GestureDetector gesture={native}>
<RNText onPress={onPress} ref={ref ?? textRef} {...rest}>
{children}
</RNText>
</GestureDetector>
);
});
export const Text = forwardRef(
(props: RNTextProps, ref: ForwardedRef<RNText>) => {
const { children, onPress, ...rest } = props;
const textRef = useRef<RNText | null>(null);
const native = Gesture.Native().runOnJS(true);

const refHandler = (node: any) => {
textRef.current = node;

if (ref === null) {
return;
}

if (typeof ref === 'function') {
ref(node);
} else {
ref.current = node;
}
};

useEffect(() => {
if (Platform.OS !== 'web') {
return;
}

const textElement = ref
? (ref as RefObject<RNText>).current
: textRef.current;

// @ts-ignore at this point we are sure that text is div
textElement?.setAttribute('rnghtext', 'true');
j-piasecki marked this conversation as resolved.
Show resolved Hide resolved
}, []);

return (
<GestureDetector gesture={native}>
<RNText onPress={onPress} ref={refHandler} {...rest}>
{children}
</RNText>
j-piasecki marked this conversation as resolved.
Show resolved Hide resolved
</GestureDetector>
);
}
);
// eslint-disable-next-line @typescript-eslint/no-redeclare
export type Text = typeof Text & RNText;
Loading