Я хочу создать текстовый компонент пользовательского интерфейса, чтобы настроить его с помощью чего-либо (стиль, шрифт, действие, ...).
У меня есть проблема, чтобы уведомить кадр к представлению js, которые представили.
TextViewManager.h
#import <Foundation/Foundation.h>
#import <React/RCTUIManager.h>
#import <React/RCTUIManagerUtils.h>
#import "RNTextView.h"
@interface TextViewManager : RCTViewManager
@end
TextViewManager.m
#import "TextViewManager.h"
@implementation TextViewManager
@synthesize bridge = _bridge;
RCT_EXPORT_MODULE(TextView)
RCT_EXPORT_VIEW_PROPERTY(text, NSString)
- (UIView *)view
{
return [[RNTextView alloc] init];
}
@end
RNTextView.h
#import <UIKit/UIKit.h>
#import <React/RCTUIManager.h>
#import <React/RCTView.h>
@interface RNTextView : RCTView
@property (nonatomic, copy) NSString* text;
@end
RNTextView.m
#import "RNTextView.h"
@implementation RNTextView
{
UITextView *_textView;
CGRect _reactViewFrame;
}
- (instancetype)initWithFrame:(CGRect)frame
{
NSLog(@"RNTextView:initWithFrame: %@", NSStringFromCGRect(frame));
self = [super initWithFrame:frame];
[self setAutoresizesSubviews:YES];
_textView = [[UITextView alloc] initWithFrame:self.bounds];
[self addSubview:_textView];
return self;
}
- (void)reactSetFrame:(CGRect)frame {
NSLog(@"RNTextView:reactSetFrame: %@", NSStringFromCGRect(frame));
_reactViewFrame = frame;
_reactViewFrame.size.height = 0.0f;
_textView.frame = _reactViewFrame;
[_textView sizeToFit];
_reactViewFrame.size.height = _textView.frame.size.height;
self.frame = _reactViewFrame;
NSLog(@"RNTextView:reactSetFrame_2: %@ %@", NSStringFromCGRect(_reactViewFrame), NSStringFromCGRect(self.frame));
[self setNeedsDisplay];
[super reactSetFrame:frame];
}
#pragma mark - PropTypes
- (void)setText:(NSString *)text
{
NSLog(@"RNTextView:setText: %@", NSStringFromCGRect(self.frame));
_textView.text = text;
}
@end
В методе setText
кадр обзора возвращает {{0, 0}, {0, 0}}
. Поэтому я установил там только текст _textView
. Я получил ширину кадра в методе reactSetFrame
, поэтому я обновил представление textview здесь.
Проблема в том, что представление в компоненте js не обновляет мой кадр, который обновил.
Это выглядит так:
![enter image description here](https://i.stack.imgur.com/GAUqb.png)
TextView
- один из пунктов в ScrollView
.
<ScrollView>
...
<TextView style={{width: '100%', ...}} text={...}/>
</ScrollView>
Предлагаете решить эту проблему? Спасибо за ваше время.