Skip to content

Commit 52fcecb

Browse files
committed
Add an example of moving focus programmatically using an observable property.
1 parent 7a9c26d commit 52fcecb

File tree

17 files changed

+239
-16
lines changed

17 files changed

+239
-16
lines changed

ReactFSharp.Android/ReactFSharp.Android.fsproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@
8383
<Compile Include="Views\View.fs" />
8484
<Compile Include="Views\ViewGroup.fs" />
8585
<Compile Include="Widget\TextView.fs" />
86+
<Compile Include="Widget\EditText.fs" />
8687
<Compile Include="Widget\Button.fs" />
8788
<Compile Include="Widget\LinearLayout.fs" />
8889
<Compile Include="Widget\Toolbar.fs" />

ReactFSharp.Android/Views/View.fs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -207,9 +207,9 @@ module private ViewProps =
207207
let private defaultOnTouch =
208208
Func<MotionEvent, bool>(fun _ -> false)
209209

210-
let defaultRequestFocus: IObservable<unit> = Observable.empty<unit>
210+
let internal defaultRequestFocus: IObservable<unit> = Observable.empty<unit>
211211

212-
let defaultProps = {
212+
let internal defaultProps = {
213213
accessibilityLiveRegion = ViewCompat.AccessibilityLiveRegionNone
214214
alpha = 1.0f
215215
backgroundColor = Color.White

ReactFSharp.Android/Views/ViewGroup.fs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ type ViewGroupProps =
105105

106106
[<CompilationRepresentation(CompilationRepresentationFlags.ModuleSuffix)>]
107107
module private ViewGroupProps =
108-
let defaultProps = {
108+
let internal defaultProps = {
109109
// View Props
110110
accessibilityLiveRegion = ViewProps.Default.accessibilityLiveRegion
111111
alpha = ViewProps.Default.alpha

ReactFSharp.Android/Widget/Components.fs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ open React.Android.Widget
88
[<CompilationRepresentation(CompilationRepresentationFlags.ModuleSuffix)>]
99
module Components =
1010
let Button = Button.reactComponent
11+
let EditText = EditText.reactComponent
1112
let FrameLayout = FrameLayout.reactComponent
1213
let GridView = GridView.reactComponent
1314
let ImageView = ImageView.reactComponent
Lines changed: 187 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,187 @@
1+
namespace React.Android.Widget
2+
3+
open Android.Content
4+
open Android.Content.Res
5+
open Android.Graphics
6+
open Android.Support.V7.Widget
7+
open Android.Views
8+
open Android.Widget
9+
open React
10+
open React.Android
11+
open React.Android.Views
12+
open System
13+
14+
type IEditTextProps =
15+
inherit ITextViewProps
16+
17+
type EditTextProps =
18+
{
19+
// View Props
20+
accessibilityLiveRegion: int
21+
alpha: float32
22+
backgroundColor: Color
23+
backgroundTintMode: PorterDuff.Mode
24+
clickable: bool
25+
contentDescription: string
26+
contextClickable: bool
27+
elevation: Single
28+
enabled: bool
29+
filterTouchesWhenObscured: bool
30+
focusable: bool
31+
focusableInTouchMode: bool
32+
hapticFeedbackEnabled: bool
33+
horizontalFadingEdgeEnabled: bool
34+
horizontalScrollBarEnabled: bool
35+
id: int
36+
layoutParameters: ViewGroup.LayoutParams
37+
onClick: Func<unit, unit>
38+
onCreateContextMenu: Func<IContextMenu, IContextMenuContextMenuInfo, unit>
39+
onDrag: Func<DragEvent, bool>
40+
onGenericMotion: Func<MotionEvent, bool>
41+
onHover: Func<MotionEvent, bool>
42+
onKey: Func<Keycode, KeyEvent, bool>
43+
onLongClick: Func<unit, bool>
44+
onSystemUiVisibilityChange: Func<StatusBarVisibility, unit>
45+
onTouch: Func<MotionEvent, bool>
46+
padding: Padding
47+
pivot: Pivot
48+
requestFocus: IObservable<unit>
49+
scrollBarSize: int
50+
scrollBarStyle: ScrollbarStyles
51+
selected: bool
52+
soundEffectsEnabled: bool
53+
systemUiVisibility: StatusBarVisibility
54+
textAlignment: TextAlignment
55+
textDirection: TextDirection
56+
transitionName: string
57+
translation: Translation
58+
verticalFadingEdgeEnabled: bool
59+
verticalScrollBarEnabled: bool
60+
verticalScrollbarPosition: ScrollbarPosition
61+
visibility: ViewStates
62+
63+
// TextView Props
64+
text: string
65+
}
66+
67+
interface IEditTextProps with
68+
// View Props
69+
member this.AccessibilityLiveRegion = this.accessibilityLiveRegion
70+
member this.Alpha = this.alpha
71+
member this.BackgroundColor = this.backgroundColor
72+
member this.BackgroundTintMode = this.backgroundTintMode
73+
member this.Clickable = this.clickable
74+
member this.ContentDescription = this.contentDescription
75+
member this.ContextClickable = this.contextClickable
76+
member this.Elevation = this.elevation
77+
member this.Enabled = this.enabled
78+
member this.FilterTouchesWhenObscured = this.filterTouchesWhenObscured
79+
member this.Focusable = this.focusable
80+
member this.FocusableInTouchMode = this.focusableInTouchMode
81+
member this.HapticFeedbackEnabled = this.hapticFeedbackEnabled
82+
member this.HorizontalFadingEdgeEnabled = this.horizontalFadingEdgeEnabled
83+
member this.HorizontalScrollBarEnabled = this.horizontalScrollBarEnabled
84+
member this.Id = this.id
85+
member this.LayoutParameters = this.layoutParameters
86+
member this.OnClick = this.onClick
87+
member this.OnCreateContextMenu = this.onCreateContextMenu
88+
member this.OnDrag = this.onDrag
89+
member this.OnGenericMotion = this.onGenericMotion
90+
member this.OnHover = this.onHover
91+
member this.OnKey = this.onKey
92+
member this.OnLongClick = this.onLongClick
93+
member this.OnSystemUiVisibilityChange = this.onSystemUiVisibilityChange
94+
member this.OnTouch = this.onTouch
95+
member this.Padding = this.padding
96+
member this.Pivot = this.pivot
97+
member this.RequestFocus = this.requestFocus
98+
member this.ScrollBarSize = this.scrollBarSize
99+
member this.ScrollBarStyle = this.scrollBarStyle
100+
member this.Selected = this.selected
101+
member this.SoundEffectsEnabled = this.soundEffectsEnabled
102+
member this.SystemUiVisibility = this.systemUiVisibility
103+
member this.TextAlignment = this.textAlignment
104+
member this.TextDirection = this.textDirection
105+
member this.TransitionName = this.transitionName
106+
member this.Translation = this.translation
107+
member this.VerticalFadingEdgeEnabled = this.verticalFadingEdgeEnabled
108+
member this.VerticalScrollBarEnabled = this.verticalScrollBarEnabled
109+
member this.VerticalScrollbarPosition = this.verticalScrollbarPosition
110+
member this.Visibility = this.visibility
111+
112+
// TextView Props
113+
member this.Text = this.text
114+
115+
[<CompilationRepresentation(CompilationRepresentationFlags.ModuleSuffix)>]
116+
module private EditTextProps =
117+
let internal defaultProps = {
118+
// View Props
119+
accessibilityLiveRegion = TextViewProps.Default.accessibilityLiveRegion
120+
alpha = TextViewProps.Default.alpha
121+
backgroundColor = TextViewProps.Default.backgroundColor
122+
backgroundTintMode = TextViewProps.Default.backgroundTintMode
123+
clickable = TextViewProps.Default.clickable
124+
contentDescription = TextViewProps.Default.contentDescription
125+
contextClickable = TextViewProps.Default.contextClickable
126+
elevation = TextViewProps.Default.elevation
127+
enabled = TextViewProps.Default.enabled
128+
filterTouchesWhenObscured = TextViewProps.Default.filterTouchesWhenObscured
129+
focusable = TextViewProps.Default.focusable
130+
focusableInTouchMode = TextViewProps.Default.focusableInTouchMode
131+
hapticFeedbackEnabled = TextViewProps.Default.hapticFeedbackEnabled
132+
horizontalFadingEdgeEnabled = TextViewProps.Default.horizontalFadingEdgeEnabled
133+
horizontalScrollBarEnabled = TextViewProps.Default.horizontalScrollBarEnabled
134+
id = TextViewProps.Default.id
135+
layoutParameters = TextViewProps.Default.layoutParameters
136+
onClick = TextViewProps.Default.onClick
137+
onCreateContextMenu = TextViewProps.Default.onCreateContextMenu
138+
onDrag = TextViewProps.Default.onDrag
139+
onGenericMotion = TextViewProps.Default.onGenericMotion
140+
onHover = TextViewProps.Default.onHover
141+
onKey = TextViewProps.Default.onKey
142+
onLongClick = TextViewProps.Default.onLongClick
143+
onSystemUiVisibilityChange = TextViewProps.Default.onSystemUiVisibilityChange
144+
onTouch = TextViewProps.Default.onTouch
145+
padding = TextViewProps.Default.padding
146+
pivot = TextViewProps.Default.pivot
147+
requestFocus = TextViewProps.Default.requestFocus
148+
scrollBarSize = TextViewProps.Default.scrollBarSize
149+
scrollBarStyle = TextViewProps.Default.scrollBarStyle
150+
selected = TextViewProps.Default.selected
151+
soundEffectsEnabled = TextViewProps.Default.soundEffectsEnabled
152+
systemUiVisibility = TextViewProps.Default.systemUiVisibility
153+
textAlignment = TextViewProps.Default.textAlignment
154+
textDirection = TextViewProps.Default.textDirection
155+
transitionName = TextViewProps.Default.transitionName
156+
translation = TextViewProps.Default.translation
157+
verticalFadingEdgeEnabled = TextViewProps.Default.verticalFadingEdgeEnabled
158+
verticalScrollBarEnabled = TextViewProps.Default.verticalScrollBarEnabled
159+
verticalScrollbarPosition = TextViewProps.Default.verticalScrollbarPosition
160+
visibility = TextViewProps.Default.visibility
161+
162+
// TextView Props
163+
text = ""
164+
}
165+
166+
type EditTextProps with
167+
static member Default = EditTextProps.defaultProps
168+
169+
[<CompilationRepresentation(CompilationRepresentationFlags.ModuleSuffix)>]
170+
module EditText =
171+
let private name = typeof<AppCompatEditText>.Name
172+
173+
let setProps (onError: Exception -> unit) (view: EditText) (props: IEditTextProps) =
174+
// FIXME: hack
175+
view.SetTextColor Color.Blue
176+
TextView.setProps onError view props
177+
178+
let private createView (context: Context) (onError: Exception -> unit) =
179+
let viewProvider () = new AppCompatEditText(context)
180+
ReactView.createView name viewProvider (setProps onError)
181+
182+
let viewProvider = (name, createView)
183+
184+
let internal reactComponent = ReactComponent.makeLazy (fun (props: EditTextProps) -> ReactNativeElement {
185+
Name = name
186+
Props = props
187+
})

ReactFSharp.Android/Widget/FrameLayout.fs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ type FrameLayoutProps =
107107

108108
[<CompilationRepresentation(CompilationRepresentationFlags.ModuleSuffix)>]
109109
module private FrameLayoutProps =
110-
let defaultProps = {
110+
let internal defaultProps = {
111111
// View Props
112112
accessibilityLiveRegion = ViewGroupProps.Default.accessibilityLiveRegion
113113
alpha = ViewGroupProps.Default.alpha

ReactFSharp.Android/Widget/GridView.fs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ type GridViewProps =
107107

108108
[<CompilationRepresentation(CompilationRepresentationFlags.ModuleSuffix)>]
109109
module private GridViewProps =
110-
let defaultProps = {
110+
let internal defaultProps = {
111111
// View Props
112112
accessibilityLiveRegion = ViewGroupProps.Default.accessibilityLiveRegion
113113
alpha = ViewGroupProps.Default.alpha

ReactFSharp.Android/Widget/ImageView.fs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ type ImageViewProps =
108108

109109
[<CompilationRepresentation(CompilationRepresentationFlags.ModuleSuffix)>]
110110
module private ImageViewProps =
111-
let defaultProps = {
111+
let internal defaultProps = {
112112
// View Props
113113
accessibilityLiveRegion = ViewProps.Default.accessibilityLiveRegion
114114
alpha = ViewProps.Default.alpha

ReactFSharp.Android/Widget/LinearLayout.fs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ type LinearLayoutProps =
134134

135135
[<CompilationRepresentation(CompilationRepresentationFlags.ModuleSuffix)>]
136136
module private LinearLayoutProps =
137-
let defaultProps = {
137+
let internal defaultProps = {
138138
// View Props
139139
accessibilityLiveRegion = ViewGroupProps.Default.accessibilityLiveRegion
140140
alpha = ViewGroupProps.Default.alpha

ReactFSharp.Android/Widget/ListView.fs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ type ListViewProps =
107107

108108
[<CompilationRepresentation(CompilationRepresentationFlags.ModuleSuffix)>]
109109
module private ListViewProps =
110-
let defaultProps = {
110+
let internal defaultProps = {
111111
// View Props
112112
accessibilityLiveRegion = ViewGroupProps.Default.accessibilityLiveRegion
113113
alpha = ViewGroupProps.Default.alpha

0 commit comments

Comments
 (0)